Open table with ado.net ?

can someone provide me with a small code example of how to open a table on the sql server, using vb 2005 using ado.net?
szx248Asked:
Who is Participating?
 
JassimiCommented:
Dim connect As New SqlConnection("Initial Catalog = Northwind;
       Data Source=(local); User ID=sa; password = ;Connect _
       Timeout=20")

connect.Open()

Console.WriteLine("Database: " & connect.Database)
Console.WriteLine("Database: " & connect.ServerVersion)
Console.WriteLine("Database: " & connect.DataSource)

Dim command As New SqlCommand("SELECT * from tablename", connect)
Dim reader As SqlDataReader = _
              command.ExecuteReader( _
              CommandBehavior.CloseConnection)

While reader.Read()
  Console.WriteLine(reader.GetSqlValue(1))
End While

0
 
curious77Commented:
What I'm trying to do is add a new record to a table.
So that leads me to two more questions -
1. Wouldn't doing this Select * be a extra overhead?
2. Now that I have a reader, how can I add a record to this table?  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.