简体   繁体   中英

Syntax error in c# for database

    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);
        }
    }

When I try to update information that is on database I take an error that is an syntax error in Update statement.

You have a comma before your WHERE clause

 "', WHERE Kimlik="

Also look into using parameters as your are leaving yourself open to SQL Injection attacks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM