locked
How to update SQLDB ? RRS feed

  • Question

  • Hi,

    I have a SQL Server 2005 and i want to update a row in a table. I have an in-memory schema (DataTable) of the DB table needs to be updated. So, this is what i did :

    1. Created a row in memory with same ID as in the row in DB
    2. Called AcceptChanges()
    3. changed a column value - this will set the rowState property of added row as modified.
    4. created a sqlcommandbuilder and sqldataadapter.
    5. called the update method of adapter.


    But the row in DB is not getting updated.


    Any ideas ?
    Monday, October 20, 2008 2:55 PM

Answers

  • You do not need to do all these steps to update, insert or delete any row in a database. You can execute any action SQL statement (INSERT/UPDATE/DELETE) using ExecuteNonQuery method of SqlCommand. See next KB with samples how to do this

     

    http://support.microsoft.com/kb/301075/en-us

     

    Friday, October 24, 2008 10:42 PM

All replies

  • You do not need to do all these steps to update, insert or delete any row in a database. You can execute any action SQL statement (INSERT/UPDATE/DELETE) using ExecuteNonQuery method of SqlCommand. See next KB with samples how to do this

     

    http://support.microsoft.com/kb/301075/en-us

     

    Friday, October 24, 2008 10:42 PM
  • The update command of the adapter updates the dataset. You need to configure the UPDATE command of command object to reflect the changes back to the db.

     

    A.D.T.

     

    Friday, October 24, 2008 10:51 PM
  • You need to configure the UPDATE command of command object to reflect the changes back to the db.


    How do i do that ?
    Thursday, October 30, 2008 9:21 AM
  • You need to pass new values using parameters, same way as described in sample for DELETE statement. Your UPDATE SQL statement would look like

     

    UPDATE TableNameHere SET MyFieldName=@ParamName1, MyOtherFieldNameHere=@ParamName2 WHERE MyIDField=@ParamName3

     

     

     

    Thursday, October 30, 2008 2:14 PM