Help with OleDbDataAdapter Update


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Help with OleDbDataAdapter Update

Hybrid View

  1. #1
    Join Date
    Apr 2007
    Posts
    8

    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.

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    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

  3. #3
    Join Date
    Apr 2007
    Posts
    8
    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.

  4. #4
    Join Date
    Apr 2007
    Posts
    8
    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 01:18 PM. Reason: Wrong code

Similar Threads

  1. Update 2 tables in a single update query
    By Nomi in forum Database
    Replies: 2
    Last Post: 01-11-2007, 02:24 PM
  2. Replies: 0
    Last Post: 06-04-2002, 11:13 AM
  3. update query
    By an in forum Database
    Replies: 0
    Last Post: 05-08-2002, 02:12 PM
  4. Replies: 0
    Last Post: 05-07-2002, 09:34 PM
  5. Urgent!!! ADO Update conflict
    By Chillu in forum VB Classic
    Replies: 0
    Last Post: 07-14-2000, 01: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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center