“System.Data.OleDb.OleDbException: 'Syntax error in INSERT INTO statement.'” [duplicate]
This question already has an answer here:
OleDBException error INSERT
2 answers
I've got an error message:
System.Data.OleDb.OleDbException: 'Syntax error in INSERT INTO statement.'
I've read through multiple questions like this, but non of their answers helped me.
This is my code:
conn.Open();
string sql = "";
sql = "insert into player(Username, Password) values(@Username, @Password)";
using (command = new OleDbCommand(sql, conn))
command.Parameters.AddWithValue("@Username", textBoxUsername.Text);
command.Parameters.AddWithValue("@Password", textBoxPassword.Text);
command.ExecuteNonQuery();
command.Dispose();
conn.Close();
The error is in the following line:
command.ExecuteNonQuery();
Does anyone know a solution for this error?
Thanks in advance!
c# database
marked as duplicate by WelcomeOverflow, Community♦ Nov 12 '18 at 21:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
OleDBException error INSERT
2 answers
I've got an error message:
System.Data.OleDb.OleDbException: 'Syntax error in INSERT INTO statement.'
I've read through multiple questions like this, but non of their answers helped me.
This is my code:
conn.Open();
string sql = "";
sql = "insert into player(Username, Password) values(@Username, @Password)";
using (command = new OleDbCommand(sql, conn))
command.Parameters.AddWithValue("@Username", textBoxUsername.Text);
command.Parameters.AddWithValue("@Password", textBoxPassword.Text);
command.ExecuteNonQuery();
command.Dispose();
conn.Close();
The error is in the following line:
command.ExecuteNonQuery();
Does anyone know a solution for this error?
Thanks in advance!
c# database
marked as duplicate by WelcomeOverflow, Community♦ Nov 12 '18 at 21:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2
What database are you connecting to? Try usingvalues(?, ?)
syntax.
– Alex K.
Nov 12 '18 at 16:08
1
OleDb is a very general purpose API that can talk to multiple databases; if you're talking to a specific database, it is usually preferable to use that database's specific API - for example,SqlConnection
/SqlCommand
etc for SQL Server. This will allow you to use that target database's full set of features, such as named parameters. OleDb is quite... well, minimal, frankly. It doesn't support named parameters, as noted by the existing answer etc.
– Marc Gravell♦
Nov 12 '18 at 16:16
2
BTW: good job on using parameters in the first place; you'd be amazed how often we see SQL concatenation of values!
– Marc Gravell♦
Nov 12 '18 at 16:17
I'm using an Acces database and thus SqlCommand does not work for me. The targetting of the database is not the problem since reading from it works perfectly well. I discoverd my problem was the use of "Password" as column name. Changing this to "Passw" solved it. Thanks for the help anyway!
– MrrrLuiigii
Nov 12 '18 at 21:52
add a comment |
This question already has an answer here:
OleDBException error INSERT
2 answers
I've got an error message:
System.Data.OleDb.OleDbException: 'Syntax error in INSERT INTO statement.'
I've read through multiple questions like this, but non of their answers helped me.
This is my code:
conn.Open();
string sql = "";
sql = "insert into player(Username, Password) values(@Username, @Password)";
using (command = new OleDbCommand(sql, conn))
command.Parameters.AddWithValue("@Username", textBoxUsername.Text);
command.Parameters.AddWithValue("@Password", textBoxPassword.Text);
command.ExecuteNonQuery();
command.Dispose();
conn.Close();
The error is in the following line:
command.ExecuteNonQuery();
Does anyone know a solution for this error?
Thanks in advance!
c# database
This question already has an answer here:
OleDBException error INSERT
2 answers
I've got an error message:
System.Data.OleDb.OleDbException: 'Syntax error in INSERT INTO statement.'
I've read through multiple questions like this, but non of their answers helped me.
This is my code:
conn.Open();
string sql = "";
sql = "insert into player(Username, Password) values(@Username, @Password)";
using (command = new OleDbCommand(sql, conn))
command.Parameters.AddWithValue("@Username", textBoxUsername.Text);
command.Parameters.AddWithValue("@Password", textBoxPassword.Text);
command.ExecuteNonQuery();
command.Dispose();
conn.Close();
The error is in the following line:
command.ExecuteNonQuery();
Does anyone know a solution for this error?
Thanks in advance!
This question already has an answer here:
OleDBException error INSERT
2 answers
c# database
c# database
edited Nov 12 '18 at 17:09
Llazar
9411516
9411516
asked Nov 12 '18 at 16:05
MrrrLuiigiiMrrrLuiigii
143
143
marked as duplicate by WelcomeOverflow, Community♦ Nov 12 '18 at 21:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by WelcomeOverflow, Community♦ Nov 12 '18 at 21:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2
What database are you connecting to? Try usingvalues(?, ?)
syntax.
– Alex K.
Nov 12 '18 at 16:08
1
OleDb is a very general purpose API that can talk to multiple databases; if you're talking to a specific database, it is usually preferable to use that database's specific API - for example,SqlConnection
/SqlCommand
etc for SQL Server. This will allow you to use that target database's full set of features, such as named parameters. OleDb is quite... well, minimal, frankly. It doesn't support named parameters, as noted by the existing answer etc.
– Marc Gravell♦
Nov 12 '18 at 16:16
2
BTW: good job on using parameters in the first place; you'd be amazed how often we see SQL concatenation of values!
– Marc Gravell♦
Nov 12 '18 at 16:17
I'm using an Acces database and thus SqlCommand does not work for me. The targetting of the database is not the problem since reading from it works perfectly well. I discoverd my problem was the use of "Password" as column name. Changing this to "Passw" solved it. Thanks for the help anyway!
– MrrrLuiigii
Nov 12 '18 at 21:52
add a comment |
2
What database are you connecting to? Try usingvalues(?, ?)
syntax.
– Alex K.
Nov 12 '18 at 16:08
1
OleDb is a very general purpose API that can talk to multiple databases; if you're talking to a specific database, it is usually preferable to use that database's specific API - for example,SqlConnection
/SqlCommand
etc for SQL Server. This will allow you to use that target database's full set of features, such as named parameters. OleDb is quite... well, minimal, frankly. It doesn't support named parameters, as noted by the existing answer etc.
– Marc Gravell♦
Nov 12 '18 at 16:16
2
BTW: good job on using parameters in the first place; you'd be amazed how often we see SQL concatenation of values!
– Marc Gravell♦
Nov 12 '18 at 16:17
I'm using an Acces database and thus SqlCommand does not work for me. The targetting of the database is not the problem since reading from it works perfectly well. I discoverd my problem was the use of "Password" as column name. Changing this to "Passw" solved it. Thanks for the help anyway!
– MrrrLuiigii
Nov 12 '18 at 21:52
2
2
What database are you connecting to? Try using
values(?, ?)
syntax.– Alex K.
Nov 12 '18 at 16:08
What database are you connecting to? Try using
values(?, ?)
syntax.– Alex K.
Nov 12 '18 at 16:08
1
1
OleDb is a very general purpose API that can talk to multiple databases; if you're talking to a specific database, it is usually preferable to use that database's specific API - for example,
SqlConnection
/SqlCommand
etc for SQL Server. This will allow you to use that target database's full set of features, such as named parameters. OleDb is quite... well, minimal, frankly. It doesn't support named parameters, as noted by the existing answer etc.– Marc Gravell♦
Nov 12 '18 at 16:16
OleDb is a very general purpose API that can talk to multiple databases; if you're talking to a specific database, it is usually preferable to use that database's specific API - for example,
SqlConnection
/SqlCommand
etc for SQL Server. This will allow you to use that target database's full set of features, such as named parameters. OleDb is quite... well, minimal, frankly. It doesn't support named parameters, as noted by the existing answer etc.– Marc Gravell♦
Nov 12 '18 at 16:16
2
2
BTW: good job on using parameters in the first place; you'd be amazed how often we see SQL concatenation of values!
– Marc Gravell♦
Nov 12 '18 at 16:17
BTW: good job on using parameters in the first place; you'd be amazed how often we see SQL concatenation of values!
– Marc Gravell♦
Nov 12 '18 at 16:17
I'm using an Acces database and thus SqlCommand does not work for me. The targetting of the database is not the problem since reading from it works perfectly well. I discoverd my problem was the use of "Password" as column name. Changing this to "Passw" solved it. Thanks for the help anyway!
– MrrrLuiigii
Nov 12 '18 at 21:52
I'm using an Acces database and thus SqlCommand does not work for me. The targetting of the database is not the problem since reading from it works perfectly well. I discoverd my problem was the use of "Password" as column name. Changing this to "Passw" solved it. Thanks for the help anyway!
– MrrrLuiigii
Nov 12 '18 at 21:52
add a comment |
1 Answer
1
active
oldest
votes
Change your sql to
sql = "insert into player(Username, Password) values(?, ?)"
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Change your sql to
sql = "insert into player(Username, Password) values(?, ?)"
add a comment |
Change your sql to
sql = "insert into player(Username, Password) values(?, ?)"
add a comment |
Change your sql to
sql = "insert into player(Username, Password) values(?, ?)"
Change your sql to
sql = "insert into player(Username, Password) values(?, ?)"
edited Nov 12 '18 at 16:22
answered Nov 12 '18 at 16:14
Peter KarmanPeter Karman
617
617
add a comment |
add a comment |
2
What database are you connecting to? Try using
values(?, ?)
syntax.– Alex K.
Nov 12 '18 at 16:08
1
OleDb is a very general purpose API that can talk to multiple databases; if you're talking to a specific database, it is usually preferable to use that database's specific API - for example,
SqlConnection
/SqlCommand
etc for SQL Server. This will allow you to use that target database's full set of features, such as named parameters. OleDb is quite... well, minimal, frankly. It doesn't support named parameters, as noted by the existing answer etc.– Marc Gravell♦
Nov 12 '18 at 16:16
2
BTW: good job on using parameters in the first place; you'd be amazed how often we see SQL concatenation of values!
– Marc Gravell♦
Nov 12 '18 at 16:17
I'm using an Acces database and thus SqlCommand does not work for me. The targetting of the database is not the problem since reading from it works perfectly well. I discoverd my problem was the use of "Password" as column name. Changing this to "Passw" solved it. Thanks for the help anyway!
– MrrrLuiigii
Nov 12 '18 at 21:52