Apply a filter with DataAdapter.Fill

  • Thread starter Thread starter Manuel
  • Start date Start date
M

Manuel

I'm using a typed dataset and would like to retrieve a specific table but
filtering the rows returned (no point in getting more than what you need,
right?). The problem is that the .Fill method of the DataAdapter will fill
the DataTable with all the rows in the table. I tried using a sqlCommand to
no avail.

How can I fill a typed DataTable with filtered rows? Something like
MyDA.Fill(MyDTable, "CustomerID=1")
 
This what I'm using now. How can I get the DataTable using a query?

-----------------------
Dim myCnn As New Data.SqlClient.SqlConnection("TheConnectionString")
Dim myDA As New MyDBTableAdapters.CustomersTableAdapter
myDA.Connection = myCnn
Dim tblCustomers As New MyDB.CustomersDataTable
myDA.Fill(tblCustomers)
myCnn.Close()
-----------------------
 
I believe that You can do this two ways.

You should be able to set your query in the data adapter's Select
Command to select only those rows that you need.

Another thing you should be able to do is use a dataview.

Example from the Visual Studio.Net Help

The following code example creates a view that shows all the products
where the units in stock is less than or equal to the reorder level,
sorted first by supplier ID and then by product name.

[Visual Basic]

Dim prodView As DataView = New DataView(prodDS.Tables("Products"), _
"UnitsInStock <= ReorderLevel",
_
"SupplierID, ProductName", _
DataViewRowState.CurrentRows)
 
You should be able to set your query in the data adapter's Select
Command to select only those rows that you need.

This is true but every time I modify the .xsd file (add a table or anything)
all my changes to the code are lost because the IDE rebuilds the entire
file. Is there any way of preventing this?
Another thing you should be able to do is use a dataview.

All DataView examples I've read so far make use of a DataTable already
filled and my purpose is filter the records retrieved, not filter them
*after* they're fetched.

news:[email protected]...
 
Back
Top