none
UPDATING DATASET TO DATABASE RRS feed

  • Question

  • Hi I have a query on UPDATING DATASET TO DATABASE


    i written a stored procedure in sql server and  called it from asp.net page and got a dataset . i binded it to a gridview.
    in the gridview user can make some changes to the content. i am facing trouble in updating the database with the values in the gridview.

    Please suggest me asap.

    I am getting error message like
    "Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information."

    the below is the code

    public static void f2(DataSet ds)

    {

    String strcon = "server=ebommapsqld01.amrs.win.ml.com\\dev01; database=RTAPS; User Id=RTAPS; Password=rtaps_password; ";
    SqlConnection con = new SqlConnection(strcon);
    String strcmd = "select * From temp1";
    SqlDataAdapter da = new SqlDataAdapter(strcmd, con);
    SqlCommandBuilder cb = new SqlCommandBuilder(da);
    con.Open();

    da.Update(ds,
    "tab1");
    con.Close();
    con.Dispose();
    }

    Monday, February 2, 2009 7:33 AM

Answers

  • You cannot use CommandBuilder here because, as the error says, there is no key column information.  (How can it figure out what row in the database it should update if it does not know how to uniquely identify a row?)

    Per relational database theory, every database table should have a primary key.  A good solution would be to modify your database so that this table has a primary key.


    • Marked as answer by Zhi-Xin Ye Friday, February 6, 2009 2:57 PM
    Monday, February 2, 2009 8:53 PM