my code is inserting some data in a Access DB. The code were fails is that (the code uses a library for download e-mails, but the error is not apparently related to that):
foreach (MimeData mime in email.Attachments)
{
string name = NumEmail + mime.SafeFileName;
string path = (@"\\pathrandom" + name);
mime.Save(path);
long length = new System.IO.FileInfo(path).Length;
String my_querry2 = "INSERT INTO Table(id, field1, field2, field3, field4)VALUES('" + path + "','" + length + "','" + name+ "','" + value3 + "','" + date + "')";
MessageBox.Show(my_querry2);
OleDbCommand cmd2 = new OleDbCommand(my_querry, conn);
cmd.ExecuteNonQuery();
}
(id, Date and value3 are variables defined out of the foreach with a foo string, date of today and foo string).
When I run this code , the insert does not occur and the ExecutedNonQuery() returns a error. It says the query did not run because it would create duplicate values. But the table is totally empty, so the 'id' can't be repeat. I tried to do the query in access and doing it:
INSERT INTO AchivosAdjuntos(id, field1, field2, field3, field4)VALUES('\\path','171','x.png','random','28/01/2015')
And it works perfectly (the values are the same that c# try to insert), inserting the values.
The connection with the DB seems fine, because before that insert I've done other that worked well.
So... what I'm doing wrong? :S