Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot Update Access Database from Datatable

Status
Not open for further replies.

MajP

Technical User
Aug 27, 2005
9,382
US

I am new to working with ADO.net

- I am using an Access database to hold my data
- At run time I create a dataset and can populate my data
- One of the datatables in the dataset is named "tblEmployeeHours"
- I have a dataadapter called "daEmployeeHours" that is used to fill the datatable
- I have a variable called "tblEmployeeHours" which references the datatable with the same name

The datatable is not bound to any UI control, but I am able to make updates to the datatable by code and verify that the datatable has been updated.

I am trying to save the updates back to the database, but nothing happens and I get no error messages
Since I built the dataadapter at runtime, I believe I also have to build the update command and define the parameters. Here is my code

Code:
        strSql = "UPDATE tblEmployee_ProjectHours SET plannedHours = @plannedHours"
        Me.daEmployeeHours.UpdateCommand = New OleDb.OleDbCommand(strSql, Me.conn)
        Me.daEmployeeHours.UpdateCommand.Parameters.Add("@plannedHours", OleDb.OleDbType.Decimal)
        Me.daEmployeeHours.UpdateCommand.Parameters("@plannedHours").SourceColumn = "plannedHours"
        Me.daEmployeeHours.Update(tblEmployeeHours)

Not sure if I built the update command and parameters correctly, and not sure of how to even error check this. The table in the database has a primary key. My understanding is that the datatable records which records have been updated, added, or deleted. Any suggestions or recommendations would be appreciated. Thanks.
 
When you change the data in the DataTable, are you calling AcceptChanges afterwards? If you are, remove that code, because that will make the DataTable show that no rows have been updated, so nothing will be updated in the database.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top