locked
Iam using Visual Basic 2010 Express and Access 2010 RRS feed

  • Question

  • I reproduced the following code to update a database and I get the error" Operation must use a updateable query"

    ds.Tables("AddressBook").Rows(inc).Item(1) = txtFirstName.Text
    ds.Tables("AddressBook").Rows(inc).Item(2) = txtLastName.Text
    
    
        da.Update(ds, "AddressBook")

    Please Help.

    Saturday, August 20, 2011 12:21 AM

Answers

  • Hi Jbh,

    Welcome to the MSDN Forum.

    Do you have set the update command for your dataadapter? If not, please try to set it first.

    This article should be helpful: http://msdn.microsoft.com/en-us/library/system.data.common.dataadapter.update(v=VS.100).aspx

    It calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the specified DataSet from a DataTable named "Table."

    The update is performed on a by-row basis. For every inserted, modified, and deleted row, the Update method determines the type of change that has been performed on it (Insert, Update or Delete). Depending on the type of change, the Insert, Update, or Delete command template executes to propagate the modified row to the data source. When an application calls the Update method, the DataAdapter examines the RowState property, and executes the required INSERT, UPDATE, or DELETE statements iteratively for each row, based on the order of the indexes configured in the DataSet. For example, Update might execute a DELETE statement, followed by an INSERT statement, and then another DELETE statement, due to the ordering of the rows in the DataTable.

    It should be noted that these statements are not performed as a batch process; each row is updated individually. An application can call the GetChanges method in situations where you must control the sequence of statement types (for example, INSERT before UPDATE). For more information, see Updating Data Sources with DataAdapters (ADO.NET).

    If INSERT, UPDATE, or DELETE statements have not been specified, the Update method generates an exception. However, you can create a SqlCommandBuilder or OleDbCommandBuilder object to automatically generate SQL statements for single-table updates if you set the SelectCommand property of a .NET Framework data provider. Then, any additional SQL statements that you do not set are generated by the CommandBuilder. This generation logic requires key column information to be present in the DataSet. For more information see Generating Commands with CommandBuilders (ADO.NET).

    I hope this will be helpful.

    Best regards,


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Mike Feng Tuesday, August 30, 2011 6:58 AM
    Tuesday, August 23, 2011 11:25 AM
  • Hello jbhII,

    I reproduced the following code to update a database and I get the error" Operation must use a updateable query" Please Help.

     

     

    ds.Tables("AddressBook").Rows(inc).Item(1) = txtFirstName.Text
    ds.Tables("AddressBook").Rows(inc).Item(2) = txtLastName.Text
    
    
    
    
    
    
    
    
    
    
    
     da.Update(ds, "AddressBook")


    I wrote this article long ago to run the query with Access Database, I hope it can help.

    http://code.msdn.microsoft.com/Esempio-di-utilizzo-file-4d9b07a8

    Regards.


    Carmelo La Monica http://community.visual-basic.it/carmelolamonica/

    WordPress  http://carmelolamonica.wordpress.com/

    • Marked as answer by Mike Feng Tuesday, August 30, 2011 6:58 AM
    Tuesday, August 23, 2011 11:59 AM

All replies