Results 1 to 4 of 4

Thread: Syntax error converting the varchar value

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    2

    Syntax error converting the varchar value

    Error: Syntax eror conerting the varchar value '[12] FirstName LastName' to a column of data type int

    Codebits:
    ****************
    ' Declare the protected objects
    Protected WithEvents drpSalesman As DropDownList

    Protected WithEvents txtDate As TextBox
    Protected WithEvents txtAmount As TextBox

    Protected WithEvents lblDebug As Label

    Protected WithEvents pnlForm As Panel
    Protected WithEvents pnlConfirm As Panel
    Protected WithEvents pnlDone As Panel

    Protected WithEvents lblSalesman As Label
    Protected WithEvents lblDate As Label
    Protected WithEvents lblAmount As Label

    'Gobal Vars

    Public conSQL As New SqlConnection( ConfigurationSettings.AppSettings( "ConnectionString" ) )
    Public cmdSQL As SqlCommand
    Public dtrSQL As SqlDataReader

    ************
    Sub SendSMS()
    Dim strSQL As String = ""
    Dim strMessage As String = ""

    strMessage &= "Compliance: " & drpSalesman.SelectedItem.Text & " $ " & String.Format("{0:#,###}", CInt(txtAmount.Text)) & vbCrLf

    '''''''''''''''''''''''''''''''''''''''
    'Saleperson Day Total
    '''''''''''''''''''''''''''''''''''''''
    strSQL = "SELECT "
    strSQL &= "SUM(amount) as total "
    strSQL &= "FROM "
    strSQL &= "SB_data as sb "
    strSQL &= "WHERE user_id = '" & drpSalesman.SelectedItem.Value & "' AND datestamp > '" & Now.ToString("d") & "' "


    conSQL.Open()
    cmdSQL = New SqlCommand(strSQL, conSQL)
    dtrSQL = cmdSQL.ExecuteReader()

    Line 160 If dtrSQL.Read() Then
    strMessage &= drpSalesman.SelectedItem.Value & " Day Total: $ " & String.Format("{0:#,###}", dtrSQL("total")) & vbCrLf
    End If

    dtrSQL.Close()

    conSQL.Close()
    *****************
    Line 160 is where the error is reported to occur.

    Any help with this would be greatly appreciated.

  2. #2
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: Syntax error converting the varchar value

    Use drpSalesman.SelectedItem.ToString


    Edit: the error you posted looks like you have the user_id column defined as an int rather than varChar()
    Last edited by bmahler; Sep 21st, 2006 at 04:18 PM.
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    2

    Re: Syntax error converting the varchar value

    Yes the user_id column is set to int, for only integar type data is entered into it.
    It is cross-referenced with several tables, whereas one of the tables is a user table that associates the user_id with the salesperson's name.

    This error does not occur when I merely post the salesperson's name initially with their immediate sale the post the company's day's sale and week sales total.

    I am trying to pull just the salesperson's day and week totals to post as well.

  4. #4
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: Syntax error converting the varchar value

    strSQL = "SELECT "
    strSQL &= "SUM(amount) as total "
    strSQL &= "FROM "
    strSQL &= "SB_data as sb "
    strSQL &= "WHERE user_id = '" & drpSalesman.SelectedItem.Value & "' AND datestamp > '" & Now.ToString("d") & "' "

    It looks like right here you are passing in a string value into user_id. number values do not require ' ' around them.

    put a break on this and check whatis being sent.
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

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