Reply
SQL and data table help please
Old 10-04-2007, 08:38 PM SQL and data table help please
Skilled Talker

Posts: 65
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?
leolim is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 10-04-2007, 08:39 PM Re: SQL and data table help please
Skilled Talker

Posts: 65
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


thanks

Last edited by leolim : 10-04-2007 at 08:42 PM.
leolim is offline
Reply With Quote
View Public Profile
 
Old 10-05-2007, 06:24 PM Re: SQL and data table help please
Learning Newbie's Avatar
Moderator

Latest Blog Post:
What Does This Look Like?
Posts: 4,733
Name: John Alexander
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.
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is online now
Reply With Quote
View Public Profile
 
Old 10-09-2007, 08:03 PM Re: SQL and data table help please
Skilled Talker

Posts: 65
based on the code above could you show me how to manipulate each row column? or maybe the column to be changed in certain row?

thanks
leolim is offline
Reply With Quote
View Public Profile
 
Old 10-09-2007, 08:04 PM Re: SQL and data table help please
Skilled Talker

Posts: 65
i am blur with this. please guide me on my problem as the problem is i can`t manipulate the column in each row. how should i do it?

thanks again
leolim is offline
Reply With Quote
View Public Profile
 
Old 10-11-2007, 08:30 PM Re: SQL and data table help please
Skilled Talker

Posts: 65
could you give me example on how to do that?
thanks
leolim is offline
Reply With Quote
View Public Profile
 
Old 10-21-2007, 08:01 PM Re: SQL and data table help please
Skilled Talker

Posts: 65
could anyone help me with my problem?
leolim is offline
Reply With Quote
View Public Profile
 
Old 10-22-2007, 06:51 PM Re: SQL and data table help please
Learning Newbie's Avatar
Moderator

Latest Blog Post:
What Does This Look Like?
Posts: 4,733
Name: John Alexander
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

Next
end if
end sub
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is online now
Reply With Quote
View Public Profile
 
Old 11-19-2007, 10:31 PM Re: SQL and data table help please
Novice Talker

Posts: 7
use

string[] ar = new string[dt.rows.count]();

for (int i = 0; dt.rows.count; i++)
{
ar[i] = dt.rows[i]["columnname"].toString();
}

Quote:
Originally Posted by leolim View Post
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?
webspinner is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to SQL and data table help please
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14680 seconds with 13 queries