October 23, 2006 at 1:51 am
Sorry for the spamI asked this same question last night, not sure if it got posted or where it ended up)
using VB.NET 2005, SQL2K
experiance: SQL >>> 8 years, VB.NET >>> 3 months, VB6 >>> 2 years (2000 to 2002).
I have created a data adapter and bound it to a DataViewGrid. I can view/scan all the data no problems here. One of the columns hold the names of our production SQL Servers and I would like to loop through that column and get the server name, and use it to create a db connection string.
I have read a lot of documentation in the last couple of days (BOL, MSDN and too many websites:crying on how easy (it is) using a data adapter to get data from your database and how efficient it is, I understand the general idea but I seem to be missing something >>> how to loop through the data table ??? <<< what I'm looking for is a code snipit or maybe some detail I missed from the information overload.I tried to get it from the DataViewGrid but I seemed to be going around in circles, got dizzy fell down.
I know I can store the server names in an array, if so, how can I fill the array from the data adapter.
Any help will be greatly appreciated, thank you in advance.
October 24, 2006 at 6:19 am
usually, you get a collection of rows from the datatable, and loop thru the rows:
Dim
dt As DataTable
Dim
a() As DataRow
Dim
dr As DataRow
Dim
SQL As String
dt = New DataTable
SQL = "SELECT * FROM SOMETABLE"
daHDS.LoadDataTable(SQL, dt)
a = dt.Select
For i = 0 To a.Length - 1
dr = a(i)
'do something with dr!SERVERNAME or dr("SERVERNAME") -- same thing two different syntaxes
next i
Lowell
October 24, 2006 at 5:55 pm
alternative way to loop if you want all the rows (dt is the datatable)
For Each row As DataRow In dt.Rows
'Do stuff with row
Next
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply