Solved

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

Posted on 2006-06-13
1
203 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now