1

When i write this code i'm taking

System.Data.OleDb.OleDbException (0x80040E14): Syntax error in UPDATE statement. message.(c#, access(SayacGun, SayacToplam are integers and Tarih is dateTime))

OleDbConnection dbBaglanti2 = new OleDbConnection(VTYolu);
dbBaglanti2.Open();
string Ekle2 = "UPDATE Sys_Sayac SET SayacGun = @Gun, SayacToplam = @Toplam, WHERE Tarih = @Tarih";
OleDbCommand Komut2 = new OleDbCommand(Ekle2, dbBaglanti2);
Komut2.Parameters.AddWithValue("@Gun", int.Parse(OkunanGun));
Komut2.Parameters.AddWithValue("@Toplam", Convert.ToInt32(OkunanToplam) + 1);
Komut2.Parameters.AddWithValue("@Tarih", DateTime.Now.ToShortDateString());
Komut2.ExecuteNonQuery();
dbBaglanti.Close();
5
  • DateTime.Now contains also the seconds. Very improbable that you can find a record with that condition. And when you transform a date in a string then anything can happen there. also that you update the wrong records. Use parameters of type DateTime and forget about AddWithValue. Commented Sep 29, 2017 at 22:47
  • If tarih is DateTime than remove ToShortDateString. I have to remember "dbBaglanti". "Did you open your baglanti?" Commented Sep 29, 2017 at 23:33
  • Can you give me an example @Steve. Thansk. Commented Sep 30, 2017 at 7:25
  • Thanks @T.S. i correct it. Commented Sep 30, 2017 at 7:26
  • If the field Tarih is of type DateTime on the DataBase then you don't use a string to query on it but a real DateTime otherwise any kind of wrong conversion could happen. Second, if the field contains only Dates with time always zero, using now will work only when Now is midnight. If instead it contains also the Time part then you need to use a range >= and <= to search for records not Now. Commented Sep 30, 2017 at 7:33

1 Answer 1

4

You should remove the comma "," before the WHERE clause,

string Ekle2 = "UPDATE Sys_Sayac SET SayacGun = @Gun, SayacToplam = @Toplam WHERE Tarih = @Tarih";

For more information check details of update syntax here

Sign up to request clarification or add additional context in comments.

1 Comment

After working 18hours. my brain has died. I spend 3 hour for a comma ",". I will kill it. Thanks a lot @4D1C70.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.