Results 1 to 2 of 2

Thread: vb.net sqlconnection err

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Location
    chennai
    Posts
    90

    vb.net sqlconnection err

    Hi

    i got the error

    type is not defined: 'SqlConnection'

    How to add a reference to Sql in VB.Net??

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    ' Open a connection to the database.
    Dim strConnection As String = _
    "Data Source=192.168.0.1; Initial Catalog=Northwind;" _
    & "Integrated Security=True"
    Dim cn As SqlConnection = New SqlConnection(strConnection)
    cn.Open()

    ' Set up a data set command object.
    Dim strSelect As String = "SELECT * FROM Customers WHERE City = 'London'"
    Dim dscmd As New SqlDataAdapter(strSelect, cn)

    ' Load a data set.
    Dim ds As New DataSet()
    dscmd.Fill(ds, "LondonCustomers")

    ' Close the connection.
    cn.Close()

    ' Do something with the data set.
    Dim dt As DataTable = ds.Tables.Item("LondonCustomers")
    Dim rowCustomer As DataRow
    For Each rowCustomer In dt.Rows
    Response.Write(rowCustomer.Item("CompanyName"))
    Next


    End Sub

    Thanks
    akalya

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Have you imported the System.Data namespace?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width