|
-
Jun 10th, 2003, 04:50 PM
#1
Thread Starter
Fanatic Member
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:
Dim oCB As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(oAdp)
Dim oComm As OleDb.OleDbCommand = oCB.GetUpdateCommand()
Try
'-- Updates the Database with the new item list
oAdp.Update(dsMyItems, "MyItems")
Catch ex As OleDb.OleDbException
Console.WriteLine(ex.Message)
End Try
'-- Close the connection, we dont need to keep it open (or do we?)
oConn.Close()
but the Try code catches an error when records have been added or delete.
-
Jun 10th, 2003, 07:14 PM
#2
Lively Member
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
-
Jun 11th, 2003, 07:43 AM
#3
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|