Solved

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

Posted on 2006-06-13
1
217 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:VBdotnet2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
imperial_p79 earned 500 total points
ID: 16900325
I am assuming that your Me.ToolStripTextBox1.Text value is 'ANTON'. In the query you are comparing this value against OrderID = 'Me.ToolStripTextBox1.Text' which is an integer field.

so change the query to

SELECT * FROM ORDERS WHERE CUSTOMERID=  '" & Me.ToolStripTextBox1.Text & "'"

Hope this helps

For select case statement, the syntax follows as

        Select Case <variablename>
            Case "value1"
            Case "value2"
            Case Else

        End Select
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question