Nel

Nel

  • NA
  • 716
  • 1.1m

Update oledbcommand doesn't update the data in the database

Jul 10 2013 6:20 AM
Hello,

I have a problem with Update OleDB command. It doesn't update the data in the MS access database.

Here is my code for the button which should perform the update command:

 OleDbCommand command = new OleDbCommand();

            command.Connection = conn;

            command.CommandText = "Update tablename set Imeprezime=?, EMB=?, Adresa=?, RegBr=?, GarBr=?, ZapBr=?, DataKaz=?, DataDosp=?, OdzDok=?, Platil=?, DataPlak=?, Kontrolor=? where Rbr=?";
            command.Parameters.AddWithValue("@imeprez", txtImePrez.Text);
            command.Parameters.AddWithValue("@EMB", txtEmb.Text);
            command.Parameters.AddWithValue("@adresa", txtAdresa.Text);
            command.Parameters.AddWithValue("@RegBr", txtReg.Text);
            command.Parameters.AddWithValue("@GarBr", Convert.ToInt32(txtGbr.Text));
            command.Parameters.AddWithValue("@ZapBr", txtZap.Text);
            command.Parameters.AddWithValue("@DataKaz", dateTimePicker1.Value.Date);

            string dateInString = Convert.ToString(dateTimePicker1.Value);

            DateTime startDate = DateTime.Parse(dateInString);

            if (Convert.ToString(startDate.DayOfWeek) == "Friday")
            {
                startDate = startDate.AddDays(3);
            }
            else if (Convert.ToString(startDate.DayOfWeek) == "Saturday")
            {
                startDate = startDate.AddDays(2);
            }
            else if (Convert.ToString(startDate.DayOfWeek) == "Sunday")
            {
                startDate = startDate.AddDays(1);
            }

            DateTime expiryDate = startDate.AddDays(10);
            dateTimePicker2.Value = expiryDate;

            command.Parameters.AddWithValue("@DataDosp", dateTimePicker2.Value);
            command.Parameters.AddWithValue("@OdzDok", txtDok.Text);
            command.Parameters.AddWithValue("@Platil", checkBox1.Checked);
            command.Parameters.AddWithValue("@DataPlak", dateTimePicker3.Value.Date);
            command.Parameters.AddWithValue("@Kontr", txtKontr.Text);
            command.Parameters.AddWithValue("@rbr", comboBox1.SelectedIndex);
            conn.Open();
            command.ExecuteNonQuery();
            conn.Close();

            try
            {
                conn.Open();
                _dataSet.Clear();
                OleDbDataAdapter oleDBDataAdapter1 = new OleDbDataAdapter(new OleDbCommand("Select * from Kazneni order by Imeprezime asc", conn));
                command.ExecuteNonQuery();
                oleDBDataAdapter1.Fill(_dataSet, "Kazneni");
            }

            finally
            {
                conn.Close();

            }


Can anybody help me please what is the problem, where I make a misktake?
Thanks

Answers (12)