Creative2 Posted January 9, 2003 Posted January 9, 2003 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 Quote
Leaders quwiltw Posted January 9, 2003 Leaders Posted January 9, 2003 what is the data type in the database for PartNumber. You'll get this error if the partnumber column is really varchar and you try to select it as if it's an int. Obviously you'll need to surround it with single quotes if it's a varchar. Quote --tim
Creative2 Posted January 9, 2003 Author Posted January 9, 2003 the datatype is varchar, i tried quotes but then it gives me syntax error, can you please give me an example of a statement? Quote
*Experts* Nerseus Posted January 9, 2003 *Experts* Posted January 9, 2003 Try GetPart = "Select PartNumber from Parts where PartNumber='" & PartNumber.Replace("'", "''") & "'" If you can't 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 don't use VB.NET and I'm a little lazy to try out a new test project :) -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.