Question regarding DataAdapter and DataTable RRS feed

  • Question


    Hi all,

    I have an app. which reads from database and bind the data to datagridview

    After the user changed the grid , I collected the data from the grid again to the DataTable and send the datatable to a routin which I expected update the Database :

    public void UpdateDBWithDataTable(dataTable oTable , string Sql)



    openConnection();//Function to Open Connection

    SqlDataAdapter oDa = new SqlDataAdapter();

    oDa.SelectCommand = new SqlCommand(Sql,Connection);

    SqlCommandBuilder cb = new SqlCommandBuilder (oDa);

    oDa.UpdateCommand = cb.GetUpdateCommand(true);







    When I try to insert new data it works good , however when I tried to update I got "Violation of Primary Key Constraint....."


    Any ideas why ? and how to solve this ?

    Thanks very much

    Thursday, May 8, 2008 2:16 PM