Results 1 to 3 of 3

Thread: Uses DataGrid to modify Access DB

  1. #1

    Thread Starter
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577

    Uses DataGrid to modify Access DB

    Hi


    Im using a DataGrid to display and modify a table from an Access DB.

    To do this I create a DataSet and fill it with MS Access database.
    I then bind the DataGrid to the Dataset so the datagrid automatically displays everything.

    I would like to use this DataGrid as my main editing for the Database including Updating/Deleting/Inserting.

    But im having trouble working out If i need to insert/update or delete.

    Basically when my application closes I wish to save the contents of the DataGrid ( which is binded to a DataSet ) back into a table in a MDB.

    So users can delete rows, add rows and update rows.
    Then when they exit, I wish to update the MDB table with all the changes from the DataSet.

    How can I do this?
    Currently this is what im doing

    VB Code:
    1. Dim oCB As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(oAdp)
    2.         Dim oComm As OleDb.OleDbCommand = oCB.GetUpdateCommand()
    3.  
    4.         Try
    5.             '-- Updates the Database with the new item list
    6.             oAdp.Update(dsMyItems, "MyItems")
    7.  
    8.         Catch ex As OleDb.OleDbException
    9.             Console.WriteLine(ex.Message)
    10.         End Try
    11.  
    12.         '-- Close the connection, we dont need to keep it open (or do we?)
    13.         oConn.Close()

    but the Try code catches an error when records have been added or delete.

  2. #2
    Lively Member
    Join Date
    Jan 2002
    Posts
    105
    The .GetUpdateCommand() only updates records. If you want to add new records you use .GetInsertCommand() and to delete the .GetDeleteCommand()

    You will need a seperate functon for each one.

    If you are using the command builder to add/update/delete then this bit doesn't look right to me, BUT! there are a number of different ways you can do the same things in .NET, so....maybe it's right.....:
    Code:
    Dim oComm As OleDb.OleDbCommand = oCB.GetUpdateCommand()
    This is the way i've done it... it works, but god only knows if it's the correct way:
    (daRt is the dataadapter)
    Code:
            'Generate the command builders
            daRt.InsertCommand = cmdBuild.GetInsertCommand
    Hope that helps you somewhat and doesn't confuse you even more

  3. #3

    Thread Starter
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577
    Thanks

    I did manage to do it. It was just my lack of knowledge of ADO.NET and databases that caused me problems. After reading through a book and some websites I managed to do it another way.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width