none
Updating records sucesses and fails!! RRS feed

  • Question

  • Hello everybody

    when i use the following code to edit recodes it works well

    no problem here.

    Code Snippet

    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]["id"] = id;

    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*/

    OleDbCommandBuilder ole=new OleDbCommandBuilder(DA);

    //update the datasource.

    try

    {

    DA.Update(dttel);

    }

    catch (DBConcurrencyException ex)

    {

    MessageBox.Show("Warning" + ex.Message,

    "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);

    }

    }

     

    But here i replaced the commandbuilder with the oledbcommand and parameters.

     i found a concurrency violation errors .

    I think that there something wrong in Sql statement or parameters.i hope i know it.?

    can any body help me ??

    Code Snippet

     

    // net framework data access and storage.

    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]["id"] = id;

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

    }

    }

     

     

    Wednesday, January 23, 2008 11:27 AM