user225269
user225269

Reputation: 10893

How to import sql in vb.net?

I mean the imports keyword on the uppermost part of the program. What should I type in there?

Upvotes: 1

Views: 17481

Answers (3)

Joel Coehoorn
Joel Coehoorn

Reputation: 416179

Imports System.Data
Imports System.Data.SqlClient

Then here's an example of how to talk to the db:

Using cn As New SqlConnection("connection string here"), _
      cmd As New SqlCommand("Sql statements here")

    cn.Open()

    Using rdr As SqlDataReader = cmd.ExecuteReader()
        While rdr.Read()
            ''# Do stuff with the data reader
        End While
    End Using
End Using

and a c# translation, because people were curious in the comments:

using (var cn = new SqlConnection("connection string here"))
using (var cmd = new SqlCommand("Sql statements here"))
{
    cn.Open();
    using (var rdr = cmd.ExecuteReader())
    {
        while (rdr.Read())
        {
            // Do stuff with the data reader
        }
    }
}

Upvotes: 4

Chris Fulstow
Chris Fulstow

Reputation: 41902

Imports System.Data.SqlClient

Upvotes: 0

Paul Sasik
Paul Sasik

Reputation: 81567

You mean:

Imports System.Data.SqlClient

Upvotes: 3

Related Questions