数据库c#中的语法错误

时间:2014-10-29 11:02:19

标签: c# database visual-studio ms-access

    public void EtiketVerisiKaydiGuncelle()
    {
        try
        {
            string sorgu = "UPDATE EtiketVerisi SET Tarih='" + this.TARIH + "', NetKG='" + this.NETKG + "', MalinCinsi='" + this.MAL + "', Musteri='" + this.MUSTERI + "', Renk='" + this.RENK + "', PartiNo='" + this.PARTINO + "', RollNo='" + this.ROLLNO + "', Barkod='" + this.BARKOD + "', WHERE Kimlik=" + this.Kimlik;

            if (bag.State == ConnectionState.Closed)
                bag.Open();
            komut.Connection = bag;
            komut.CommandText = sorgu;
            komut.ExecuteNonQuery();
            MessageBox.Show("Kayıt Güncellendi");
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

当我尝试更新数据库中的信息时,我会在Update语句中出现语法错误。

1 个答案:

答案 0 :(得分:4)

您的WHERE子句之前有逗号

 "', WHERE Kimlik="

同时考虑使用参数,因为您将自己打开SQL注入攻击