I'm unable to write new entries to a local Access 2002-2003 (.mdb) database using C#, the problem is the syntax of my cmdText property in the OleDbCommand class.
PLEASE DO NOT mention Parametized SQL statements or SQL Injection, since this is only for personal tests
Anyway, here's the command text I'm trying to use:
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Daniel\source\repos\DatabaseInteraction2\DatabaseInteraction2\SimpleDatabase.mdb";
OleDbCommand command;
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
connection.Open();
command = new OleDbCommand("Insert Into SimpleTable (userName,userPassword) Values " +
"('TestUsername','TestPassword')", connection);
try
{
command.ExecuteNonQuery();
}
catch(Exception error)
{
Console.WriteLine(error.Message
}
}
What is the correct way to perform insertions in an Access dataset? What syntax should I use? Right now, I tried it in 6 different ways, and none of them worked.
The exceptions I get are somewhat similiar to the following:
- Unknown parameters
- Directory missing
- Syntax error in "Insert Into"