0

My code is as below '''a','b','c'''.

Dim abc As String = "''a','b','c''"
sqlselect.Connection = con
sqlselect.CommandText = "insert into table1(Name1) values ('" & abc  & "')"

It gives the error:

Syntax error (missing operator)

in the query expression

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dandy
  • 467
  • 1
  • 10
  • 33

1 Answers1

4

You use parametrized query not string concatenation

Dim a As String = "'a', 'b', 'c'"

sqlselect.Connection = con
sqlselect.CommandText = "insert into table1(Name1) values (@a)"
sqlselect.Parameters.AddWithValue("@a", a)
sqlselect.ExecuteNonQuery()

This assuming you have only one column named Name1.

The parametrized queries are the only way to go because they offer protection against SQL Injections and help you treating the parsing of strings, dates, decimal numbers

Community
  • 1
  • 1
Steve
  • 213,761
  • 22
  • 232
  • 286