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

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.

LVL 1
nickmarshallAsked:
Who is Participating?
 
Ravi SinghSenior Software EngineerCommented:
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 & "')"
0
 
Ravi SinghSenior Software EngineerCommented:
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 & "')"
0
 
nickmarshallAuthor Commented:
I get error; "Operator "&" is not defined for types "string" ?
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
Ravi SinghSenior Software EngineerCommented:
Hi, whats the type of the variable CSNameNode?  
0
 
nickmarshallAuthor Commented:
Dim CSNameNode As XmlNode = XmlDoc.DocumentElement.SelectSingleNode("//CSName")
CSNameNode.InnerText.ToString()

0
 
nickmarshallAuthor Commented:
Many thanks, its working perfectly now.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.