Click here to Skip to main content
16,013,581 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have "An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll" error Additional information: "Syntax error in Update statement".

My FirmaBilgileri.cs code is here:

C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace EBC
{
    public partial class FirmaBilgileri : Form
    {

        Database datab = null;

        private void FirmaBilgileri_Load(object sender, EventArgs e)
        {

            datab = new Database();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            datab.setUnvan(textBox1.Text);
            datab.setAdres(textBox2.Text);
            datab.setTelefon(textBox3.Text);
            datab.setFaks(textBox4.Text);
            datab.setEposta(textBox5.Text);
            datab.setWeb(textBox6.Text);
            datab.setVergiD(textBox7.Text);
            datab.setVergiN(textBox8.Text);
            datab.FirmaBilgileriKayitGuncelle();
        }
    }
}


And my Database.cs code is here:

C#
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Windows.Forms;
using System.Data;
using System.Collections;
using Microsoft.VisualBasic;
using System.IO;

namespace EBC
{
    public class Database
    {
        private OleDbConnection bag = new OleDbConnection();
        private OleDbCommand komut = new OleDbCommand();
        private OleDbDataReader reader = null;
        public DataTable dtable = new DataTable();

        string Unvan;
        string Adres;
        string Telefon;
        string Faks;
        string Eposta;
        string Web;
        string VergiD;
        string VergiN;
        int Kimlik = 1;

        public Database()
        {
            string baglanti = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source = BarcodeVeritabani.mdb";
            bag.ConnectionString = baglanti;

            try
            {
                bag.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        public void FirmaBilgileriKayitGuncelle()
        {
            try
            {
                string sorgu = "UPDATE Firmabilgileri SET Unvan='" + this.Unvan + "', Adres='" + this.Adres + "', Telefon='" + this.Telefon + "', Faks='" + this.Faks + "', EPosta='" + this.Eposta + "', Web='" + this.Web + "', VergiD='" + this.VergiD + "', " + "VergiN='" + this.VergiN + "', 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);
            }
        }

        public void setUnvan(string Unvan)
        {
            this.Unvan = Unvan;
        }

        public void setAdres(string Adres)
        {
            this.Adres = Adres;
        }

        public void setTelefon(string Telefon)
        {
            this.Telefon = Telefon;
        }

        public void setFaks(string Faks)
        {
            this.Faks = Faks;
        }

        public void setEposta(string Eposta)
        {
            this.Eposta = Eposta;
        }

        public void setWeb(string Web)
        {
            this.Web = Web;
        }

        public void setVergiD(string VergiD)
        {
            this.VergiD = VergiD;
        }

        public void setVergiN(string VergiN)
        {
            this.VergiN = VergiN;
        }
    }
}


Could anyone help me?
Posted
Comments
Praveen Dselva 4-Aug-14 5:12am    
When Exception occur which point is pointed in your code
alidayan 4-Aug-14 5:13am    
komut.ExecuteNonQuery();

1 solution

Quote:
string sorgu = "UPDATE Firmabilgileri SET Unvan='" + this.Unvan + "', Adres='" + this.Adres + "', Telefon='" + this.Telefon + "', Faks='" + this.Faks + "', EPosta='" + this.Eposta + "', Web='" + this.Web + "', VergiD='" + this.VergiD + "', " + "VergiN='" + this.VergiN + "'===>,<=== WHERE Kimlik=" + this.Kimlik;

I guess the problem is the extra comma just before the WHERE clause.

I any case you should debug your code to see the runtime value of sorgu string in order to spot the SQL syntax error.
 
Share this answer
 
Comments
alidayan 4-Aug-14 5:17am    
It is worked. Thank you. Allways being like tihs :). Just a comma :)
CPallini 4-Aug-14 5:25am    
You are welcome.
(cut'n'paste comma, I guess :-) )
alidayan 4-Aug-14 8:56am    
:) Thank you again

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900