Hello All,
Sure this is something simple but it is driving me mad! I have the code below which I want to use to insert Data from my C# programme into access database.
However everytime that it tries to write to the DB it throws a error.
savedData through to savedData3 are string variables that have been populated with either numbers a "-" or text. Can anyone help as to why this wont save to my DB?
Thanks
Sure this is something simple but it is driving me mad! I have the code below which I want to use to insert Data from my C# programme into access database.
However everytime that it tries to write to the DB it throws a error.
Code:
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data source= C:\db1.mdb; Persist Security Info=False";
OleDbCommand cmd = new OleDbCommand();
try
{
conn.Open();
cmd = conn.CreateCommand();
cmd.CommandText = "INSERT INTO logData([IP Address],[Username],[Referrer],[URL])VALUES(" + savedData + ",'" + savedData1 + ",'" + savedData2 + ",'" + savedData3 + "');";
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show("Failed to connect to data source");
}
finally
{
conn.Close();
}
Thanks
Comment