Hi guys,

I am using this code to update a record after searching but it gives me error here is my code please please help

Dim con As New SqlClient.SqlConnection
        Dim strCon As String = "Data Source=ITS;Initial Catalog=Payment;Integrated Security=True"


        Dim strCommand As String = "SELECT * FROM CustomerInformation WHERE CustomerID = '" & TextBox4.Text & "'"

        'Create connection
        Dim conn As SqlConnection = New SqlConnection(strCon)

        Try
            con.ConnectionString = strCon

            Dim cm As New SqlClient.SqlCommand(strCommand, con)

            con.Open()
            Dim da As SqlDataAdapter = New SqlDataAdapter(strCommand, con)
            'create dataset
            Dim ds As DataSet = New DataSet
            'fill dataset
            da.Fill(ds, "CustomerInformation")
            'get data table
            Dim dt As DataTable = ds.Tables("CustomerInformation")

            With dt
                .Rows(0)("CustomerName") = TextBox1.Text
                .Rows(0)("FName") = TextBox2.Text
                .Rows(0)("IdCardNo") = TextBox3.Text
                .Rows(0)("CustomerID") = TextBox4.Text
                .Rows(0)("Address") = TextBox5.Text
            End With

            'update customers table
            da.Update(ds, "CustomerInformation")
            MessageBox.Show("Record Updated Successfully......", "ALI ENTERPRISES", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MsgBox("Error: " & ex.ToString & vbCrLf)
        Finally
            If con.State = ConnectionState.Open Then

                con.Close()
            End If
        End Try
    End Sub

You should change this line in your code

Dim conn As SqlConnection = New SqlConnection(strCon)

to

Dim con As SqlConnection = New SqlConnection(strCon)

The rest of your code reffers to the variable con vs conn

Dim con As SqlConnection = New SqlConnection(strCon)

After replacing it gives same error

This question has already been answered. Start a new discussion instead.