none
Insert from DataTableAdapter is not reflected in the MS Access Database! RRS feed

  • Question

  • Hi, I am using MS Access as my Database and using Dataset for retrieval and update for my WPF app.

     The data is shown in a datagrid without issues. However, when i try to insert data using the following code,

    the insert is completed successfully, but the new row cannot be seen in the Access file.

       
       var add = new AddressBookDataSet();
    
       adc.Fill(add.Address);
    
       var v = add.Address.NewAddressRow();
    
       v.StreetAddress = textBoxStreetAddress.Text;
    
       v.AtPost = textBoxAtPost.Text;
    
       v.Taluka = textBoxTaluka.Text;
    
       v.District = textBoxDistrict.Text;
    
       v.State = textBoxState.Text;
    
       v.Pincode = textBoxPincode.Text;
    
       v.PhoneNumber1 = textBoxContact1.Text;
    
       v.PhoneNumber2 = textBoxContact2.Text;
    
       v.PhoneNumber3 = textBoxContact3.Text;
    
       v.PhoneNumber4 = textBoxContact4.Text;
    
       v.FaxNumber1 = textBoxFax1.Text;
    
       v.FaxNumber2 = textBoxFax2.Text;
    
       add.Address.AddAddressRow(v);
    
       add.Address.AcceptChanges();
    
       //adc.Insert(textBoxStreetAddress.Text, textBoxAtPost.Text, textBoxTaluka.Text, textBoxDistrict.Text,
     textBoxState.Text, textBoxPincode.Text, textBoxContact1.Text, textBoxContact2.Text, textBoxContact3.Text, 
    textBoxContact4.Text, textBoxFax1.Text, textBoxFax2.Text);
    
    

    What could be the issue here? I checked the .accdb is not marked read-only! here,

    1 field v.Id has been ommitted as the Id field is an autonumber! also, before going with creating a new Row, I tried the adc.Insert (i.e. TableAdapter.Insert) yet it doesn't update in the DB!!


    Monday, April 11, 2011 9:14 AM

Answers

  •  

    Hi manish.k,

    Welcome! I edited the format of your post to let it readable.

    According to your description, when you want to insert new row to database, you should call your TableAdapter to update your DataSet:

    var add = new AddressBookDataSet();  adc.Fill(add.Address);
      var v = add.Address.NewAddressRow();
      v.StreetAddress = textBoxStreetAddress.Text;
      v.AtPost = textBoxAtPost.Text;
      v.Taluka = textBoxTaluka.Text;
      v.District = textBoxDistrict.Text;
      v.State = textBoxState.Text;
      v.Pincode = textBoxPincode.Text;
      v.PhoneNumber1 = textBoxContact1.Text;
      v.PhoneNumber2 = textBoxContact2.Text;
      v.PhoneNumber3 = textBoxContact3.Text;
      v.PhoneNumber4 = textBoxContact4.Text;
      v.FaxNumber1 = textBoxFax1.Text;
      v.FaxNumber2 = textBoxFax2.Text;
      add.Address.AddAddressRow(v);
      adc.Update(add );//change is here
    
     

    Please try it and let me know the feedback.

    Have a nice day.


    Alan Chen[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 manish.k Wednesday, April 13, 2011 8:23 AM
    Tuesday, April 12, 2011 2:48 AM
    Moderator
  • Make sure you are looking at the corrct Access Database!  I believe that if you are using the DataDesigners to setup your connections, it will create a copy of your database and any modifications/edits will be done to this "copy" database.  I don't remember exactly where, but check in the Debug folder for the database that contains your inserts/updates.
    James Crandall ~ http://javitechnologies.com Spatial Database Solutions
    • Marked as answer by manish.k Wednesday, April 13, 2011 8:23 AM
    Tuesday, April 12, 2011 1:05 PM

All replies

  •  

    Hi manish.k,

    Welcome! I edited the format of your post to let it readable.

    According to your description, when you want to insert new row to database, you should call your TableAdapter to update your DataSet:

    var add = new AddressBookDataSet();  adc.Fill(add.Address);
      var v = add.Address.NewAddressRow();
      v.StreetAddress = textBoxStreetAddress.Text;
      v.AtPost = textBoxAtPost.Text;
      v.Taluka = textBoxTaluka.Text;
      v.District = textBoxDistrict.Text;
      v.State = textBoxState.Text;
      v.Pincode = textBoxPincode.Text;
      v.PhoneNumber1 = textBoxContact1.Text;
      v.PhoneNumber2 = textBoxContact2.Text;
      v.PhoneNumber3 = textBoxContact3.Text;
      v.PhoneNumber4 = textBoxContact4.Text;
      v.FaxNumber1 = textBoxFax1.Text;
      v.FaxNumber2 = textBoxFax2.Text;
      add.Address.AddAddressRow(v);
      adc.Update(add );//change is here
    
     

    Please try it and let me know the feedback.

    Have a nice day.


    Alan Chen[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 manish.k Wednesday, April 13, 2011 8:23 AM
    Tuesday, April 12, 2011 2:48 AM
    Moderator
  • Make sure you are looking at the corrct Access Database!  I believe that if you are using the DataDesigners to setup your connections, it will create a copy of your database and any modifications/edits will be done to this "copy" database.  I don't remember exactly where, but check in the Debug folder for the database that contains your inserts/updates.
    James Crandall ~ http://javitechnologies.com Spatial Database Solutions
    • Marked as answer by manish.k Wednesday, April 13, 2011 8:23 AM
    Tuesday, April 12, 2011 1:05 PM
  • Earlier I had used the above code and but i modified it in the hope of success.
    The code in your reply is correct, although that wasn't the issue in my case.
    Thanks :)
    Wednesday, April 13, 2011 8:22 AM
  • Thank you, I finally also saw it and found the changes being done in the DB file /bin/Debug folder.

    Thanks :)

    Wednesday, April 13, 2011 8:24 AM