syntax for the row in the Dataset?

geor68

New member
Joined
Nov 6, 2011
Messages
4
Programming Experience
Beginner
Hi,

I have the following code which populates a DataGrid from an Excel spreadsheet.

Dim myData As New OleDbDataAdapter("SELECT [Field1], [Field1],[Field2],[Field3],[Field4],[Field5],[Field6]FROM [Sheet1$] WHERE Condition1 ORDER BY [Field1]", strConn)
myData.TableMappings.Add("Table", "Fields")
myData.Fill(myDataset)
DataGrid1.DataSource = myDataset.Tables(0).DefaultView
DataGrid1.DataBind()

The DataGrid has a page size of 10. There are 15 rows in the dataset which are displayed on the DataGrid as 10 on page 1 and the other 5 on Page 2. I want to loop through the 15 rows looking for Field1 being a specific value. How do I do this? I know I need a For Next Loop, its the syntax for the row in the Dataset thats stumped me, Any pointers would be much appreciated.

Thanks in advance.
 
First up, what's the point of the DataSet? All you're using is one DataTable so why not just create one DataTable? Create a DataTable, pass it to Fill and then assign it to the DataSource. Using the DefaultView is pointless to because that's where the data comes from when binding a DataTable anyway.

As for loop through the records, the DataTable has a Rows collection that you loop through like any other list.
 
Back
Top