none
concurrency violation the update command affect 0 of the expected 1 records RRS feed

  • Question

  • Good morning everybody.

    when i use the following code i find this exception "concurrency violation the update command affect 0 of the expected 1 records"

    somebody help me.

     

    public void UpdateRec(
               int id,
             string name,
             string title,
             string home_phone,
             string mobile_phone,
             string address,
             string notes)

            {
                /* First
                         * ..........................
                         * Update the record from RAM
                         ............................*/
                DataRow[] DR = dttel.Select("id=" + id);
                DR[0].BeginEdit();
                DR[0]["name"] = name;
                DR[0]["title"] = title;
                DR[0]["home_phone"] = home_phone;
                DR[0]["mobile_phone"] = mobile_phone;
                DR[0]["address"] =address;
                DR[0]["notes"] = notes;
                DR[0].EndEdit();
                /* Second
                          * .........................
                          * Update the record from Harddisk*/
                string Update_str = "update  tel set " +
                "
    name=@name," +
                "
    title=@title," +
                "
    home_phone=@home_phone," +
                "
    mobile_phone=@mobile_phone," +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
                "
    address=@address," +
                "
    notes=@notes " +
                "where
    id=@id  " ;

                //defining sqlcommands.
               OleDbCommand Update_cmd = new OleDbCommand(Update_str, MyConnection.connect());
                //defining the parameters and the textboxes binded to it.
                //(1)id,int,nn
                Update_cmd.Parameters.Add("@id", OleDbType.Integer, 100, "id" );
                Update_cmd.Parameters["@id"].Value = id;
               //(2)name,char(50),nn
                Update_cmd.Parameters.Add("@name", OleDbType.LongVarChar, 100, "name");
                Update_cmd.Parameters["@name"].Value = name;
               //(3)title,char(10),n
                Update_cmd.Parameters.Add("@title", OleDbType.LongVarChar, 100, "title");
                Update_cmd.Parameters["@title"].Value = title;
                //(4)home_phone,char(10),n
                Update_cmd.Parameters.Add("@home_phone", OleDbType.LongVarChar, 100, "home_phone");
                Update_cmd.Parameters["@home_phone"].Value = home_phone;
                  //(5)home_mobile,char(10),n
                Update_cmd.Parameters.Add("@mobile_phone", OleDbType.LongVarChar, 100, "mobile_phone");
                Update_cmd.Parameters["@mobile_phone"].Value = mobile_phone;
                //(6)address,char(50),n
                Update_cmd.Parameters.Add("@address", OleDbType.LongVarChar, 100, "address");
                Update_cmd.Parameters["@address"].Value = address;
                //(7)notes,text,n
                Update_cmd.Parameters.Add("@notes", OleDbType.LongVarChar, 100, "notes");
                Update_cmd.Parameters["@notes"].Value = notes;
                 //(defining the adapter command
                DA.UpdateCommand = Update_cmd;
               //update the datasource.
                try
                {
                    DA.Update(dttel);
                }
                catch (DBConcurrencyException ex)
                {
                    MessageBox.Show("Warning" + ex.Message,
                   "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
           }

    Monday, January 21, 2008 8:02 PM

All replies

  • Hello,

    I am not sure but I think that you should add id parameter at end and not at first.

    But you are not on the good forum! Go to here, you will have probably more answers.

    You should look at Entity Framework (this forum). It's easier and cleaner to do what you want.

     

    Monday, January 21, 2008 8:40 PM