Problem in Updating Dataset to database using SQL Adapter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sachinkale123
    New Member
    • Jul 2007
    • 37

    Problem in Updating Dataset to database using SQL Adapter

    I am using SQL Adapter to select data from a table in SQL Server Database. After creating Object I am filling that to a datatable. Assum that dataset has 5 row. After that I m updating that dataset and add 3 more rows. but not able to update that dataset to database table.
    My code is following.

    SqlDataAdapter SDA = new SqlDataAdapter( "Select * from WFF", DAC.Conn); SDA.Fill(dt,"WF F");
    //Updates dt here
    SDA.Update(dt);

    It does not update to database so please tell me wheres the problem and solution as i have wasted near about whole day on this.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    See if this helps.

    Comment

    • sachinkale123
      New Member
      • Jul 2007
      • 37

      #3
      Hi,

      My Code is
      : SqlDataAdapter SDA = new SqlDataAdapter( "Select * from WFF", DAC.Conn); SDA.Fill(dt,"WF F");
      //Updates dt here
      SDA.Update(dt);

      suppose 'dt' contains
      1 Sachin 10000
      2 Sam 10000
      3 XYZAB 20000

      I add 2 more rows
      now my dt looks like
      1 Sachin 10000
      2 Sam 10000
      3 XYZAB 20000
      10 David 10000
      15 Rick 50000

      I m able to see 5 record in dt.
      but update that dt to 'WFF' table.
      compiler is not giving any error at SDA.Update(dt); but now also updatin table.

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #4
        Based on the code you provided, you never gave your DataAdapter an INSERT or UPDATE command.

        The data adapter must have these commands, as well as a DELETE command, to successfully update your table. You can use a CommandBuilder.

        Read this howto. I show you how to use commandbuilders and how to update datasets.

        Comment

        Working...