Refreshing Dataset

Deepa

New member
Joined
May 9, 2006
Messages
4
Programming Experience
Beginner
I have an table with a single colum in MSAccess.I have used the wazard to create dataset ..etc and connected it to my datagridview. this displays all the existing records

WHAT I DID:- i have used the foll code to add new records to the above table
VB.NET:
Dim NEWrow As DataRow = MYTESTDataSet.Tables("MYTABLE").NewRow()
        NEWrow(0) = "AAA"
        MYTESTDataSet.Tables("MYTABLE").Rows.Add(NEWrow)
        MYTESTDataSet.Tables("MYTABLE").AcceptChanges()

WHAT HAPPENS in VB:- I can see the data ("AAA") being added to the datagrid..no eorror

WHAT HAPPENS IN Access:- it still has the same number of records.. the new additions ("AAA") is not added. hence when i close the vb form and run again..the datagrid shows only the records present before adding the "AAA" via code

Please help me to add-update to access - retiveit back in VB
I am sure that i might be missing smothing here..just cant put my finger to it
help me please

Thank you
 
Thank you very much,.. the explaination using the USB stick.. made the entire story clear.. now things are getting saved and i can see them when i close and run the app again... after i did "COPY IF NEWER".. however...

my original code
VB.NET:
Dim NEWrow As DataRow = MYTESTDataSet.Tables("MYTABLE").NewRow()
        NEWrow(0) = "AAA"
        MYTESTDataSet.Tables("MYTABLE").Rows.Add(NEWrow)
        MYTESTDataSet.Tables("MYTABLE").AcceptChanges()
did not work..ie.. the new records ("AAA") was not added..
then i used
VB.NET:
MYTABLETableAdapter.Insert("BBB")
        MYTABLETableAdapter.Update(MYTESTDataSet)

THIS added now records ("BBB") to my database
the bottomline is.. this works.. but is it ok to work this way?

u r article had been a great help
thank you
 
but is it ok to work this way?

I've always used .Update and it works perfectly. It can also be used to add and delete rows as well, from MSDN:
- Use the TableAdapter.Update method when your application uses datasets to store data. The Update method sends all changes (updates, inserts, and deletes) to the database.
- Use the TableAdapter.Insert method when your application uses objects to store data, or when you want finer control over creating new records in the database

Glad it helped!
 
Last edited:
my original code
VB.NET:
Dim NEWrow As DataRow = MYTESTDataSet.Tables("MYTABLE").NewRow()
Do not do this. Use this instead:

Dim newRow as MYTESTDataSet.MYTABLERow = MYTESTDataSet.MYTTABLE.NewMYTABLERow()

It's known as using Typed objects rather than unTyped objects. It then means you can do this:

newRow.FirstColumnName = "AAA"

You might not understand the difference but a good OO programmer will always choose typed over untyped in the same way that a good programmer almost never used Variant in VB6

VB.NET:
        MYTESTDataSet.Tables("MYTABLE").Rows.Add(NEWrow)
        MYTESTDataSet.Tables("MYTABLE").[B]AcceptChanges[/B]()
did not work..ie.. the new records ("AAA") was not added..

That's because you called AcceptChanges, which made the newly Added row become an Unchanged one. Because there is no point sending an unchanged row to a database, it is not sent, so it is never saved to the DB

Do not call AcceptChanges yourself, until you really know how this all works

then i used
VB.NET:
MYTABLETableAdapter.Insert("BBB")
        MYTABLETableAdapter.Update(MYTESTDataSet)

THIS added now records ("BBB") to my database

That is thanks to the Insert call, and is NOTHING to do with the Update call

Update takes any changed (Added, Modified, Deleted) rows from a datatable and sneds the changes back to the database.

Insert is known as a DBDirect method; it directly inserts the data you specified, into the database, without that data being part of a dataset.

I think you should do a lot of reading of the DW2 links in my signature

this works.. but is it ok to work this way?
Not really. DBDirect is only used for data that you wont show to the user. You wouldnt go to the laborious process of pulling data out of all on screen text boxes and using Insert to send it to the db, you would just bind the textboxes and then use Update to save the changes
 
Back
Top