Vb.Net Escape Reserved Keywords in SQL Statement

vb.net escape reserved keywords in sql statement

You're not enclosing your values in quotation marks. Try this:

datalayer.getDataTable(String.Format(
"INSERT INTO users (username, password, [level]) VALUES ('{0}', '{1}', '{2}')",
username, password, level))

However, as Andrew says, you should really use parameters. In Access SQL (David W Fenton will come along shortly and say it's "Jet" SQL) you have to use positional parameters. Your statement would then look like this:

INSERT INTO users (username, password, [level]) VALUES (?, ?, ?)

You'd need to create OleDbParameter objects with the correct values, and an OleDbCommand with the text above to execute in order to do your insert.

How can I avoid errors around reserved words when querying Access?

I agree with the comments but the immediate cause of your issue is that "Password" is a reserved word in Access so you need to escape it if you want to use it as an identifier. You already know how to do that because you're already doing it with the table name, which you have poorly named with a space in it.

how to escape key words in c#?

You need to add @ to variable names:

@class

But it is a very bad practice. Every time you name your variable as a keyword a kitten dies :)

Incorrect syntax near the keyword 'user'- How to write my query - VB.net and Sql Server

Try this

     SELECT NAME, EMAIL, PASSWORD FROM [USER] 
WHERE ID =(SELECT USERID FROM EMPLOYERUSER WHERE EMPUSERTYPE=1 AND EMPLOYERID= 96)

This is because you have used keyword USER

can i use a keyword as a propertyname in vb .net?

Surround it with square brackets

Public Class JsonResponse
Public result As JsonResult
Public [error] As String
Public id As Integer
End Class

HTH



Related Topics



Leave a reply



Submit