none
Adding records to an Access 2007 database using VB 2010 Express Edition

    Question

  • Hi Everyone,

    I am not able to add records in an Access 2007 database using VB 2010 Express Edition. I have read other posts and followed them but still I am not sucessful. I have the connection to the access database as MS Access Database, therefore it has the OLEDB connection (not the Jet 4.0). I am using the project instance in binding the text boxes to the fieldnames in the Access database. Did I miss something? I am also using Windows Vista Ultimate.

    Below is the code.

     

    Private Sub cmd_Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles

    cmd_Save.Click

     

    Dim newFixedAssetRow As DataRow

    = BwdInventoryDataSet1.FixedAsset.NewRow

    newFixedAssetRow(

    "RRNo"

    ) = txt_RRNo.Text

    newFixedAssetRow(

    "AssetCode"

    ) = txt_AssetCode.Text

    newFixedAssetRow(

    "Description"

    ) = txt_Description.Text

    newFixedAssetRow(

    "Quantity"

    ) = Val(txt_Qty.Text)

    newFixedAssetRow(

    "Unit"

    ) = txt_Unit.Text

    newFixedAssetRow(

    "Amount"

    ) = Val(txt_Amount.Text)

    newFixedAssetRow(

    "Remarks"

    ) = txt_Remarks.Text

    BwdInventoryDataSet1.FixedAsset.Rows.Add(newFixedAssetRow)

     

    End Sub

    Thanks,

    AJ

     
    Tuesday, June 21, 2011 1:16 PM

Answers

All replies

  • Looks like you need to call the Update method for your TableAdapter. See if the below link helps:

    http://msdn.microsoft.com/en-us/library/ms233812(v=VS.100).aspx

     


    Paul ~~~~ Microsoft MVP (Visual Basic)
    • Marked as answer by AJ0520 Tuesday, June 28, 2011 2:59 PM
    Tuesday, June 21, 2011 1:19 PM
  • Hi Paul,

    Yes, it works!!! My issue now is the db being updated is the one located in the bin folder. The db that needs to be updated is located in another folder which is the path declared in the dataset properties. What should I need to do?

    Thanks again.

    AJ

    Tuesday, June 21, 2011 2:43 PM
  • If I understand your question correctly I believe that you need to set the Copy to Output Directory property of the database in your project to Do not copy.
    Paul ~~~~ Microsoft MVP (Visual Basic)
    Tuesday, June 21, 2011 4:08 PM
  • Hi Paul,

    After changing the property to Do not copy, I am getting an error 'OleDbException was unhandled' error. It is still looking for the database at the bin\Debug folder. Do I need to start a new project? I have tried rebooting the computer, and it is still giving the same error message.

    Thanks.

    AJ

    Wednesday, June 22, 2011 2:05 PM
  • Hi Aj,

    Where do you set the access db file path? Please change it to a relative path rathere than the absolute path.

    Best regards,


    Mike Feng [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.

    Thursday, June 23, 2011 8:11 AM
    Moderator
  • Hi Mike,

    I set the path when I created the mdb. No specific path inside the code. Do I need to set it inside the code?

    Regards,

    AJ

    Thursday, June 23, 2011 1:54 PM
  • Check in your App.Config file to make certain there isn't a path to that folder there. Also, could you post the exact text of the exception?
    Paul ~~~~ Microsoft MVP (Visual Basic)
    Thursday, June 23, 2011 3:14 PM
  • Hi Paul, Here is the exact text of the exception... OleDbException was unhandled. Could not find file "C:\....bin\Debug\MyDatabase.accdb". The error happens during the form load on the line ... "FixedAssetTableAdapter.Fill(MyDataSet1.FixedAsset). The full path in the app.config file is pointing to the target folder and not to the output folder (..bin\Debug folder). I also opened the app.config file and the connection string is as follows: connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\MyDatabase.accdb" AJ
    Friday, June 24, 2011 2:02 PM
  • Hi Aj,

    I didn't reproduce your scenario, Here is my the key parts setting, please try again:

     

     I hope this will be helpful.

    Best regards,


    Mike Feng [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.


    • Edited by Mike FengModerator Monday, June 27, 2011 2:24 AM change picture
    • Marked as answer by AJ0520 Tuesday, June 28, 2011 2:59 PM
    Monday, June 27, 2011 2:18 AM
    Moderator
  • Hi Mike,

    I followed what you provided in the screenshot. I was able to save records to the database, but it is the database located in the bin\debug folder. Based on what I have researched, this is normal during development stage (the changes in the database are in the bin\debug copy of the database.) But when it is deployed, it will save in the path as indicated in the full path property of the database properties. I still have to see if this is true. I will be deploying the first phase of the software by next week. I will let you what the result would be.

    Thanks,

    AJ

    Monday, June 27, 2011 1:42 PM
  • AJ,

    You create a follow up question.

    That is not done in these forums, mark the reply from Mike F as answer and give him some helpfull points.

    Then create a followup qeustion for your newone about how to set that datasource to another location in the connectionstring.

     


    Success
    Cor
    Monday, June 27, 2011 2:59 PM
  • Hi Cor,

    Thanks for the info. My apologies. 

    Regards,

    Cor

    Tuesday, June 28, 2011 3:01 PM