Link to home
Start Free TrialLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

Northwind database - ERROR - Syntax error converting the varchar value 'MYINPUT' to a column of data type int.

I keep gettig error : Syntax error converting the varchar value 'ANTON' to a column of data type int. What does it means?
There is a lot of "IF" in my code. How would I use Select case in this case? Your help is greatly appreciated.

 Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click

        Dim connectionString As String = "Data Source=SUPERMAN;Initial Catalog=Northwind;Integrated Security=True"
        Dim con As New SqlConnection(connectionString)
        Dim selectSQL As String = "select *from orders where orderid = '" & Me.ToolStripTextBox1.Text & "'"
        Dim da As New SqlDataAdapter(selectSQL, con)
        Dim ds As New DataSet
        Dim Id As String = Me.ToolStripTextBox1.Text.Trim

        If Me.ToolStripTextBox1.Text = Nothing Then
            MessageBox.Show("Please enter OrderId", "Empty Field", _
            MessageBoxButtons.OK, MessageBoxIcon.Information)

        End If

        If Me.ToolStripComboBox1.SelectedIndex = 1 Then

            If Regex.IsMatch(Id, "^\d{5}$") Then
                da.Fill(ds, "orders")
                If ds.Tables("orders").Rows.Count = 0 Then
                    MsgBox("Record not found")
                Else
                    Me.DataGridView3.DataSource = ds.Tables("orders")
                End If
            Else
                MsgBox("Id needs to be a 5 digit number only")
            End If


        End If

        If Me.ToolStripComboBox1.SelectedIndex = 0 Then
            If Regex.IsMatch(Id, "^\w{5}$") Then  ' -----------------------------SUPPOSED TO BE 5 CHARACTOR LONG

                da.Fill(ds, "customers")   **************************ERROR HERE Syntax error converting the varchar value 'ANTON' to a column of data type int.

                If ds.Tables("customers").Rows.Count = 0 Then
                    MsgBox("CustomerId not found")
                Else
                    Me.DataGridView3.DataSource = ds.Tables("Customers")


                End If

                MsgBox("Please enter CustomerID")


            End If

        End If

       



    End Sub
ASKER CERTIFIED SOLUTION
Avatar of imperial_p79
imperial_p79

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial