I have a DataTable populated with samo data/values and I want to read data from DataTable and pass it to a string variable.
I have this code:
DataTable dr_art_line_2 = ds.Tables["QuantityInIssueUnit"];
I have a countert like this:
for (int i = 1; i <= broj_ds; i++ )
{
QuantityInIssueUnit_value => VALUE FROM DataTable
QuantityInIssueUnit_uom => VALUE FROM DataTable
}
Is this possible or not? If yes then how to pass data from DataTable to those variables?
Thanks!
I think it will work
for (int i = 1; i <= broj_ds; i++ )
{
QuantityInIssueUnit_value = dr_art_line_2[i]["Column"];
QuantityInIssueUnit_uom = dr_art_line_2[i]["Column"];
}
You can do it using the foreach loop
DataTable dr_art_line_2 = ds.Tables["QuantityInIssueUnit"];
foreach(DataRow row in dr_art_line_2.Rows)
{
QuantityInIssueUnit_value = Convert.ToInt32(row["columnname"]);
}
For VB.Net is
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "database path")
Dim cmd As New OleDb.OleDbCommand
Dim dt As New DataTable
Dim da As New OleDb.OleDbDataAdapter
con.Open()
cmd.Connection = con
cmd.CommandText = sql
da.SelectCommand = cmd
da.Fill(dt)
For i As Integer = 0 To dt.Rows.Count
someVar = dt.Rows(i)("fieldName")
Next
Source: Stackoverflow.com