WHERE clause on table adapter from variable?

HeavenCore

Well-known member
Joined
Apr 10, 2007
Messages
77
Location
Bolton, England
Programming Experience
1-3
No idea what i'm doing on this one lol.

Basically i have a Form with a databound form (frmJobs), works fine via a simple Select * table adapter binding. On this form i have several buttons, one for example is 'Vew Quotes'.

I have a View Quotes Form which allows the user to scroll through all quotes using a detailsview databind.

The 'View Quotes' button needs to fire up frmQuote but in this case only populate it with Quotes where QuotesJob_fk (the foreign key in quotes table relating it to the jobs table) is equal to the current job being viewed on the frmJobs. What is the most efficient way of doing this?

any help and example would be awesome,

Best Regards

J.
 
Some people do prefer books and Wrox generally produce good ones; Microsoft's Tutorial is free, and solves the problem, which IMHO makes it better value but I'm interested to know - do wrox advocate the same method that Microsoft do?

I dont have the book; would you mind doing a quick compare for me?
 
yea they do both use the same @parameter based method, the wrox book goes into more detail obviously, with screen shots, also explaining how to specify the parameter from code:

VB.NET:
[COLOR=black]Me.TblWageTableAdapter.FillByJobID(Me.DsWages.tblWage, cboJobID.Text)[/COLOR]

in this instance FillByJobID is the new query i added to the Wage Table Adapter.

so basically on my table adapter i added a new query with a simple WHERE = @jobid

then simply populate a combobox with all keys, passing the combo box value to the parameter.
 
Cool cool.. the relevant section of the MSDN tutorial in the article i pointed you to, is:

You can add a WHERE clause to the original query using the <A onclick="javascript:Track('ctl00_LibFrame_ctl24|ctl00_LibFrame_ctl25',this);" href="http://msdn2.microsoft.com/en-us/library/wta78a9t(VS.80).aspx">Search Criteria Builder Dialog Box.
To create a parameterized query and controls to enter the parameters

  1. Select the DataGridView control, and then choose Add Query on the Data menu.
  2. Type FillByCity in the New query name area on the Search Criteria Builder Dialog Box.
  3. Add WHERE City = @City to the query in the Query Text area.
    The query should be similar to the following:
    SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax
    FROM Customers
    WHERE City = @City
    hbsty6z7.note(en-US,VS.80).gif
    Note Access and OleDb data sources use the question mark '?' to denote parameters, so the WHERE clause would look like this: WHERE City = ?.
  4. Click OK to close the Search Criteria Builder dialog box.
    A FillByCityToolStrip is added to the form.


var ExpCollDivStr = ExpCollDivStr;ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl27ca72986,";var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl27img,";Testing the Application
Running the application opens your form ready to take the parameter as input.
To test the application

  1. Press F5 to run the application.
  2. Type London into the City text box and then click FillByCity.
    The data grid is populated with customers that meet the parameterization criteria. In this example, the data grid only displays customers that have a value of London in their City column.

Looking at the code generated by this process would lead you to derive perrty much the same as the book, though it is, indeed, a little less in-depth..
 
Back
Top