We help IT Professionals succeed at work.

VB.net MySQL Query - Expected end of statement error?

nickmarshall
nickmarshall asked
on
Medium Priority
313 Views
Last Modified: 2011-10-03
Experts,

I have the following query;

Dim SQLQuery As String = "Insert Into Hardware (ID, CSName) VALUES ('" "', '" CSNameNode "')"

I am getting "expected end of statement" error.... I cannot see what is wrong with this query.

Comment
Watch Question

Ravi SinghSenior Software Engineer

Commented:
Hi, you need to concatenate the string with the CSNameNode string using the & operator:

   Dim SQLQuery As String = "Insert Into Hardware (ID, CSName) VALUES (' ', '" & CSNameNode & "')"

Is ID an auto incremenet field in your database? If so you don't need to include it in the insert statement:

   Dim SQLQuery As String = "Insert Into Hardware (CSName) VALUES ('" & CSNameNode & "')"

Author

Commented:
I get error; "Operator "&" is not defined for types "string" ?
Ravi SinghSenior Software Engineer

Commented:
Hi, whats the type of the variable CSNameNode?  

Author

Commented:
Dim CSNameNode As XmlNode = XmlDoc.DocumentElement.SelectSingleNode("//CSName")
CSNameNode.InnerText.ToString()

Senior Software Engineer
Commented:
Try:

Dim SQLQuery As String = "Insert Into Hardware (ID, CSName) VALUES (' ', '" & CSNameNode.InnerText & "')"

or with the other sql query:

Dim SQLQuery As String = "Insert Into Hardware (CSName) VALUES ('" & CSNameNode.InnerText & "')"

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Many thanks, its working perfectly now.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.