Iterating (looping) through a strongly typed DataSet

rleiman

New member
Joined
Jan 31, 2013
Messages
1
Programming Experience
Beginner
Hi Everyone,

I'm learning about DataSets and would like to loop through a strongly typed DataSet created in the Visual Studio DataSet designer.

Can you show me the rest of the coding I need to add so I can extract the data from the column called "ClassName"?

VB.NET:
[COLOR=#00008B]Dim[/COLOR] strClassName [COLOR=#00008B]As[/COLOR] [COLOR=#00008B]String[/COLOR] = [COLOR=#800000]""
[/COLOR][COLOR=#00008B]Dim[/COLOR] objAadapter [COLOR=#00008B]As[/COLOR] [COLOR=#00008B]New[/COLOR] DataSetSchedulesTableAdapters.DataTableTableAdapterSchedules
[COLOR=#00008B]Dim[/COLOR] objDataTable [COLOR=#00008B]As[/COLOR] DataSetSchedulesTableAdapters.DataTableTableAdapterSchedules

<I need a way [COLOR=#00008B]to[/COLOR] fill the table [COLOR=#00008B]with[/COLOR] data from> = objAadapter.GetDataByAll(TextBoxSearch)
[COLOR=#00008B]
For[/COLOR] [COLOR=#00008B]Each[/COLOR] row [COLOR=#00008B]As[/COLOR] System.Data.DataRow [COLOR=#00008B]In[/COLOR] objDataTable    
   strClassName = row.ClassName 
[COLOR=#00008B][FONT=Consolas]Next
[/FONT][/COLOR]

Thanks.
 
Just infer the types:
Dim table = objAadapter.GetDataByAll(TextBoxSearch)
For Each row In table    
   Dim cname = row.ClassName 
Next

Hover the variables to see how the compiler interprets these types.
Inferred the type of the table is in this form: projectNamespace.datasetName.tableName
Inferred the type of the row is in this form: projectNamespace.datasetName.rowName
 
You've already got it. GetDataByAll returns a DataTable, so assign it to the objDataTable variable that you declared above. If you want to populate an existing DataTable instead then you obviously have to create a New one first, then call FillByAll and pass that DataTable as an argument.
 
Back
Top