Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Leaders
Posted
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.
--tim
  • *Experts*
Posted

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

"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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...