could anyone show me how i could fill a DataTable, then loop through its DataRows and fire off a new query for each of them in asp.net please
currently i used
Code:
protected sub page_load(byval sender as object, byval e as system.eventargs)
If not ispostback then
Dim mycn As SqlConnection
Dim myda As SqlDataAdapter
Dim ds As DataSet
mycn = New SqlConnection("server = localhost;uid=sa;password=;database=school")
myda = New SqlDataAdapter("select * FROM student", mycn)
ds = New DataSet
myda.Fill(ds, "student")
Dim dc As DataColumn
Dim dr As DataRow
For Each dr In ds.Tables(0).Rows
Dim trow As New TableRow
For Each dc In ds.Tables(0).Columns
Dim tcell As New TableCell
tcell.Controls.Add(New LiteralControl(dr(dc.ColumnName).ToString))
trow.Cells.Add(tcell)
Next
Table1.Rows.Add(trow)
Next
end if
end sub
output:
1 john 123 west wing 1
2 maggie north wing 25# 1
3 tony blok 2 2
and i fires everything out and i couldn`t do any changes or execute new query at the middle of the execution.what i want is to get the last value of every row which is "1 1 2" in each row to execute another sql query as the to replace the "1 1 2" with data executed based on the value
could anyone help me out with this?
please show me how i could fill a DataTable, then loop through its DataRows and fire off a new query for each of them in asp.net based on my problem above please
You're already doing pretty much all the parts you need. Looks like you filled a DataTable (ds.Tables(0)) and looped through the rows. Just whatever query you need to use to look up more data inside the for each loop, the same way you did up top.
protected sub page_load(byval sender as object, byval e as system.eventargs)
If not ispostback then
Dim mycn As SqlConnection
Dim myda As SqlDataAdapter
Dim ds As DataSet
mycn = New SqlConnection("server = localhost;uid=sa;password=;database=school")
myda = New SqlDataAdapter("select * FROM student", mycn)
ds = New DataSet
myda.Fill(ds, "student")
Dim dc As DataColumn
Dim dr As DataRow
For Each dr In ds.Tables(0).Rows
Dim trow As New TableRow
For Each dc In ds.Tables(0).Columns
Dim tcell As New TableCell
tcell.Controls.Add(New LiteralControl(dr(dc.ColumnName).ToString))
trow.Cells.Add(tcell)
Next
Table1.Rows.Add(trow)
Dim anotherTableAdapter As New SqlDataAdater("select * from somewhere", mycn)
Dim newDataTable as new DataTable
anotherTableAdapter.Fill(newDataTable)
' Do something with this new data here
for (int i = 0; dt.rows.count; i++)
{
ar[i] = dt.rows[i]["columnname"].toString();
}
Quote:
Originally Posted by leolim
could anyone show me how i could fill a DataTable, then loop through its DataRows and fire off a new query for each of them in asp.net please
currently i used
Code:
protected sub page_load(byval sender as object, byval e as system.eventargs)
If not ispostback then
Dim mycn As SqlConnection
Dim myda As SqlDataAdapter
Dim ds As DataSet
mycn = New SqlConnection("server = localhost;uid=sa;password=;database=school")
myda = New SqlDataAdapter("select * FROM student", mycn)
ds = New DataSet
myda.Fill(ds, "student")
Dim dc As DataColumn
Dim dr As DataRow
For Each dr In ds.Tables(0).Rows
Dim trow As New TableRow
For Each dc In ds.Tables(0).Columns
Dim tcell As New TableCell
tcell.Controls.Add(New LiteralControl(dr(dc.ColumnName).ToString))
trow.Cells.Add(tcell)
Next
Table1.Rows.Add(trow)
Next
end if
end sub
output:
1 john 123 west wing 1
2 maggie north wing 25# 1
3 tony blok 2 2
and i fires everything out and i couldn`t do any changes or execute new query at the middle of the execution.what i want is to get the last value of every row which is "1 1 2" in each row to execute another sql query as the to replace the "1 1 2" with data executed based on the value
could anyone help me out with this?