A SQL Statement Question

Creative2

Active member
Joined
Jan 7, 2003
Messages
31
Location
Toronto, Canada
Hi guys,

I have following codes in my application:

Dim PartNumber as String

PartNumber=lstResults.Selecteditem (List box, assume assigning a value "XXXXXX" to the variable)

Dim GetPart As String

GetPart="Select PartNumber from Parts where PartNumber=" & PartNumber (Variable)

when I execute the query I get the following error:

Invalid Column Name: XXXXXX (Value of variable PartNumber)

Anyone knows why this happening??

I would really appreciate your help.

Jazz
 
what is the data type in the database for PartNumber. Youll get this error if the partnumber column is really varchar and you try to select it as if its an int. Obviously youll need to surround it with single quotes if its a varchar.
 
Try
Code:
GetPart = "Select PartNumber from Parts where PartNumber=" & PartNumber.Replace("", "") & ""

If you cant tel, there are some single and double quotes right next to each other above. If you cut and past to notepad you might be able to see them better.

Also note that I may not have the syntax right for Replace. I dont use VB.NET and Im a little lazy to try out a new test project :)

-Nerseus
 
Back
Top