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 SinghConnect With a Mentor Senior 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
All Courses

From novice to tech pro — start learning today.