• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 490
  • Last Modified:

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?
0
szx248
Asked:
szx248
1 Solution
 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now