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
Using Union and Count(*) Together in SQL Query
How to Release Possible Postgres Row Locks
How to Make Create or Replace View Work in SQL Server
Select Top N Rows for Each Group
Remove Uniqueness of Index in Postgresql
Best Table Design for Application Configuration or Application Option Settings
What Is the Scala Type Mapping for All Spark SQL Datatype
SQL One to One Relationship VS. Single Table
How to Show Blank Record in SQL If Duplicate Rows Exists
Selecting Distinct Combinations
Access SQL Query: Find the Most Recent Date Entry for Each Employee for Each Training Course
Db2 - Returning the Top 5 of Each Category
Update Statement Using with Clause
Select Column, If Blank Select from Another
SQL Query in Spark/Scala Size Exceeds Integer.Max_Value
Delete the 'First' Record from a Table in SQL Server, Without a Where Condition