none
no change in db after update - please help RRS feed

  • Question

  •                    

     OleDbDataAdapter adapter = new OleDbDataAdapter();
                            string queryString = "SELECT * FROM tasks";
                            OleDbConnection connection = new OleDbConnection(cn.ConnectionString);
                            adapter.SelectCommand = new OleDbCommand(queryString, connection);
                            OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);

                            connection.Open();

                            
                            adapter.Fill(ds.Tables["Tasks"]);

                            //code to modify data in dataset here

                            adapter.Update(ds);

                            return ds;
                        }
    Thursday, October 8, 2009 3:18 PM

Answers

  • Update should be on DataTable not DataSet.

    Adapter.update(ds.Tables["Tasks"])
    John
    • Marked as answer by Yichun_Feng Wednesday, October 14, 2009 6:32 AM
    Thursday, October 8, 2009 5:36 PM
  • Do you call AcceptChanges method before calling Update method? If yes, remove it.


    Val Mazur (MVP) http://www.xporttools.net
    • Marked as answer by Yichun_Feng Wednesday, October 14, 2009 6:32 AM
    Friday, October 9, 2009 10:29 AM
    Moderator
  •  

    Hi urania,

     

    Add to Val's reply, there are other two points in updating issue,

     

    1) Remember to set primary key of your table in database.

     

    2) If the database is Access, the commands that generated by commandbuilder will not work in some situations. For example, you have column name “user”. It will collide with the reservation words in Access. If it is that case, you’ll have to write your own update command and remember to add “[]” around the column name.

     

     

    If you have any questions or concerns, please update the thread and we will have a further discussion.

     

     

    Best Regards

    Yichun Feng

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Yichun_Feng Wednesday, October 14, 2009 6:32 AM
    Monday, October 12, 2009 7:41 AM

All replies

  • Update should be on DataTable not DataSet.

    Adapter.update(ds.Tables["Tasks"])
    John
    • Marked as answer by Yichun_Feng Wednesday, October 14, 2009 6:32 AM
    Thursday, October 8, 2009 5:36 PM
  • Do you call AcceptChanges method before calling Update method? If yes, remove it.


    Val Mazur (MVP) http://www.xporttools.net
    • Marked as answer by Yichun_Feng Wednesday, October 14, 2009 6:32 AM
    Friday, October 9, 2009 10:29 AM
    Moderator
  •  

    Hi urania,

     

    Add to Val's reply, there are other two points in updating issue,

     

    1) Remember to set primary key of your table in database.

     

    2) If the database is Access, the commands that generated by commandbuilder will not work in some situations. For example, you have column name “user”. It will collide with the reservation words in Access. If it is that case, you’ll have to write your own update command and remember to add “[]” around the column name.

     

     

    If you have any questions or concerns, please update the thread and we will have a further discussion.

     

     

    Best Regards

    Yichun Feng

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Yichun_Feng Wednesday, October 14, 2009 6:32 AM
    Monday, October 12, 2009 7:41 AM