TableAdapter.Update(dataTable) Not Working
-
Monday, August 27, 2012 12:27 PM
I feel as though I have a strong knowledge of the DataSet concept and how it relates and works with a Database through the Adapter but after running the following procedure, with no errors, I check the database and nothing has been changed. Here's the beef of where I'm having problems:
NOTE: IS_CI_ID = is a field of the Inventory record (I)nventory(S)ite_(C)ustomer(I)nformation_ID"
(I apologize for the cryptic naming.)--------------------------------------------- CODE --------------------------------------------
For Each row_Inv In dt_Inv.Rows 'iterate through all inventory records
If row_Inv.IS_CI_ID = row_Orig.CI_ID Then 'does this inv record have the deleted CI_ID?
row_Inv.IS_CI_ID = "DELETED" 'set the CI_ID to deleted
End If
Nextadapter_Inv.Update(dt_Inv) 'update database with changes
------------------------------------------------ END CODE ----------------------------------------After running this code with no errors, I check the database and nothing has been changed. I look in the database for the field "IS_CI_ID" in all the records and there are none set to "DELETED". As well, my actual code has an event raised right after setting the field to "DELETED" and hence know that the changes have been made to the dataTable. And further, before my Update method is called, I use the following statement to assure changes have been made to the DataTable (dt_inv) and indeed hundreds have been:
MsgBox("Changes, Inv: " & dt_Inv.GetChanges.Rows.Count.ToString)
Thank you very much for even looking my problem over! Of course if you see something in error please let me know. Have a great day!
Glenn
Glenn T. Kitchen VB.NET Forums
- Edited by Glenn T. Kitchen, αβθ-Coding Monday, August 27, 2012 12:28 PM
- Edited by Glenn T. Kitchen, αβθ-Coding Monday, August 27, 2012 12:29 PM typos
All Replies
-
Monday, August 27, 2012 12:43 PM
I would check the below link first (#2) if you are not getting any errors:
Paul ~~~~ Microsoft MVP (Visual Basic)
- Marked As Answer by Glenn T. Kitchen, αβθ-Coding Sunday, September 02, 2012 12:16 AM
-
Tuesday, August 28, 2012 4:44 AMModerator
Hi Glenn,
Thanks for you post.
As I read your thread, I’m just wondering the way you update the data to database.
The code showed for us is only showed that one column in a specific record has be set to “deleted”. Please add a breakpoint on the “next” line, and check whether there is one record in datatable have been changed.
The code of following steps has missing. So would you like to share the code about update command in adapter?
I look forward your reply.
Mark Liu-lxf [MSFT]
MSDN Community Support | Feedback to us
- Edited by Mark Liu-lxfModerator Tuesday, August 28, 2012 4:45 AM
-
Sunday, September 02, 2012 12:14 AMHi Mark; The last line of my code is what is supposed to update the actual database "adapter_Inv.Update(dt_Inv)". I have since solved the problem which was: 1. My database was being copied to the output directory via the Database Properties settings. This was definitely a problem! 2. (I don't know if this mattered but I changed it anyway) I wasn't using BeginEdit and EndEdit on the dataTable. Thank you for your efforts in helping - seriously! Glenn
Glenn T. Kitchen VB.NET Forums
-
Sunday, September 02, 2012 12:16 AM
Thank you Paul, #2 was indeed the problem.
(2) The other common problem is that in Visual Studio, there is an option to copy your database file to the output folder of your project. Usually this is done with an Access MDB file, or a SQL Server MDF file, when you add the database file to your project.
Glenn T. Kitchen VB.NET Forums

