Could anybody help me please. I have a situation, where, I receive two error message 1. Syntax error in INSERT INTO, also 2. Failed to open a rowset.
Please see the code below. Your help is very appriciated as this problem is driving me round a bend!
private
void WriteToDatabase()
{
OleDbConnection myConn =
null;
const string fileName = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data source= C:\C#\Tabels\Tab1.mdb";
try
{
myConn =
new OleDbConnection(fileName);
}
catch(OleDbException ex)
{
MessageBox.Show(ex.Message);
}
string insertStatement = "INSERT INTO MKFac(LiveF,UpperM,LowerM,UpperF,LowerF,S600,Output)VALUES(30,30,30,30,30,30,'Hello')";
myConn.Open();
MessageBox.Show(myConn.Database);
OleDbCommand insertCommand =
new OleDbCommand(insertStatement,myConn);
try
{
int count = insertCommand.ExecuteNonQuery();
MessageBox.Show ("Wrote : " + count);
insertCommand.Dispose();
}
catch (OleDbException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (myConn.State == ConnectionState.Open)
myConn.Close();
}
}
P.S. I have checked my Access database tabel and etc.
Many thanks
Behzad.