Data Conversion error

Results 1 to 2 of 2

Thread: Data Conversion error

  1. #1
    Join Date
    Dec 1969

    Default Data Conversion error

    I have a drop down list being run at server with each drop down item having a different value. I am passing that value into a SQL statement being built on the fly. I am stuffing that vlaue into a variable and then into the SQL statement as follows:<BR><BR><BR> Dim SQL As String<BR> Dim strChoice As String <BR> strChoice= CType(ddlist.SelectedItem.Value, String)<BR><BR> SQL = "SELECT * From Table Where &#039;" & strChoice & "&#039; = 1 "<BR><BR>I am getting this error"<BR>"Syntax error converting the varchar value &#039;(the name of value passed)&#039; to a column of data type int."<BR><BR>The type of value being passed in the variable is a field with a value type of bit. If I type out the name of the field in the SQL statement dirrectly it works. What do I need to change?

  2. #2
    Join Date
    Dec 1969

    Default Doesn't the error tell you???

    THINK about what you are creating for a SQL statement. Let&#039;s say you passed ZAMBONI and that&#039;s the value you get in strChoice.<BR><BR>So then your SQL string becomes<BR> SELECT * FROM Table Where &#039;ZAMBONI&#039; = 1<BR><BR>SO you are comparing the *STRING* ZAMBONI to the number 1. Why would you expect anything but an error message?<BR><BR>HINT: Dump the &#039;...&#039; marks!<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts