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.
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()
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.
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.