John, as most mentioned here, it would be beneficial to go through
some basic ADO.Net material, this stuff should come to you pretty
quickly.
But in the meantime, here's the basic method to get a dataset filled
with your sql query (and for the experts, please feel free to chime in
with corrections, I can certainly use the input as well):
The following is with System.Data.SqlClient imported:
Imports System.Data.SqlClient << this goes before the class
declaration.
Dim conn1 As New
SqlConnection("server='serverAddr';uid='userId';pw d='yurPass';database=somethingName;")
Dim sqlString As String = "select * from zipCode"
Dim adapter1 As New SqlDataAdapter(sqlString, conn1)
Dim ds1 As New Data.DataSet
adapter1.Fill(ds1)
adapter1.Dispose()
MsgBox(ds1.Tables(0).Rows(0).Item(1))
You'll be able to access the tables, rows and columns of your result
off the dataset.
Also, if you're looking to loop through your result you can get a
count of the number of rows by:
ds1.Tables(0).Rows.Count
This is what I use, it's by no means the only or the best way of
retrieving data, but seems to work ok.
- Joe
On Jan 9, 6:50*pm, "John" <J...@nospam.infovis.co.ukwrote:
Hi
I have an sql statement in a string variable SQLStr and I also have an
oledbconnection Conn with my database. What can I do from here to run the
sql and get a handle to the resultset in my app? I want to be able to go
through the records in the resultset in a loop and read the field values.
Thanks
Regards