-
Help with OleDbDataAdapter Update
So I created a C# Windows Application using VS .NET 2005. I am connecting to a simple Access Database that has two columns. I placed a DataGridView on the form. I connect with the database successfully. Data rows are read correctly into the grid view via TableAdapter.Fill in form load. Then upon exit, I call TableAdapter.Update(DataSet.Table). That succeeds. In fact, Update returns the number of updated rows. I tested with modifying one row, it returns 1 or modifying four rows it returns 4. I even did a loop displaying contents of DataSet.Table and verified in the debug window that the content is the updated content. Problem is data does not get persisted to the database. I open Access Database or relaunch the application and old data is still there. I searched over the internet and people were saying you need to set update command. Framework already does that for me. I found the code where update command is set.
-
So me your update code...
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
Code:
In form load: patientIdMapTableAdapter.Fill(patientIdMapDataSet.PatientIdMap);
Upon pressing persist button: patientIdMapTableAdapter.Update(patientIdMapDataSet.PatientIdMap);
The fill correctly populates the data as I see all the rows in grid view. I also verify that patientIdMapDataSet.PatientIdMap contains the updated data based on my modifications in grid view within persist button by displaying contents of each row. The call to Update passes and returns the number of updated rows. Unfortunately, the data in the database does not get updated.
-
Code:
this._adapter.UpdateCommand = new global::System.Data.OleDb.OleDbCommand();
this._adapter.UpdateCommand.Connection = this.Connection;
this._adapter.UpdateCommand.CommandText = "UPDATE `PatientIdMap` SET `ActualPatientId` = ?, `SyprosoftPatientId` = ? WHERE (" + "(`ActualPatientId` = ?) AND ((? = 1 AND `SyprosoftPatientId` IS NULL) OR (`Sypro" + "softPatientId` = ?)))";
this._adapter.UpdateCommand.CommandType = global::System.Data.CommandType.Text;
this._adapter.UpdateCommand.Parameters.Add(new global::System.Data.OleDb.OleDbParameter("ActualPatientId", global::System.Data.OleDb.OleDbType.VarWChar, 0, global::System.Data.ParameterDirection.Input, ((byte)(0)), ((byte)(0)), "ActualPatientId", global::System.Data.DataRowVersion.Current, false, null));
this._adapter.UpdateCommand.Parameters.Add(new global::System.Data.OleDb.OleDbParameter("SyprosoftPatientId", global::System.Data.OleDb.OleDbType.VarWChar, 0, global::System.Data.ParameterDirection.Input, ((byte)(0)), ((byte)(0)), "SyprosoftPatientId", global::System.Data.DataRowVersion.Current, false, null));
this._adapter.UpdateCommand.Parameters.Add(new global::System.Data.OleDb.OleDbParameter("Original_ActualPatientId", global::System.Data.OleDb.OleDbType.VarWChar, 0, global::System.Data.ParameterDirection.Input, ((byte)(0)), ((byte)(0)), "ActualPatientId", global::System.Data.DataRowVersion.Original, false, null));
this._adapter.UpdateCommand.Parameters.Add(new global::System.Data.OleDb.OleDbParameter("IsNull_SyprosoftPatientId", global::System.Data.OleDb.OleDbType.Integer, 0, global::System.Data.ParameterDirection.Input, ((byte)(0)), ((byte)(0)), "SyprosoftPatientId", global::System.Data.DataRowVersion.Original, true, null));
this._adapter.UpdateCommand.Parameters.Add(new global::System.Data.OleDb.OleDbParameter("Original_SyprosoftPatientId", global::System.Data.OleDb.OleDbType.VarWChar, 0, global::System.Data.ParameterDirection.Input, ((byte)(0)), ((byte)(0)), "SyprosoftPatientId", global::System.Data.DataRowVersion.Original, false, null));
Essentially, I created a two column Access database that would map an actual patient Id to an anonymous patient Id that we generate. This has to do with HIPAA rules and this database will reside on the client's machine. Above code was auto-generated.
Last edited by spudRay; 10-14-2009 at 12:18 PM.
Reason: Wrong code
Similar Threads
-
By Nomi in forum Database
Replies: 2
Last Post: 01-11-2007, 01:24 PM
-
By Lewis Keim in forum VB Classic
Replies: 0
Last Post: 06-04-2002, 10:13 AM
-
Replies: 0
Last Post: 05-08-2002, 01:12 PM
-
By Alwin in forum Database
Replies: 0
Last Post: 05-07-2002, 08:34 PM
-
By Chillu in forum VB Classic
Replies: 0
Last Post: 07-14-2000, 12:06 PM
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks