Update database after copy

redm

Member
Joined
Sep 20, 2005
Messages
8
Programming Experience
Beginner
Hi I'm using a
VB.NET:
Expand Collapse Copy
OleDb.OleDbConnection()
to connect to an access database.

The following code *is* working

VB.NET:
Expand Collapse Copy
Dim cb As New OleDb.OleDbCommandBuilder(DB.da_B) 

dsNewRow = DB.ds_B.Tables("B_Data").NewRow()

dsNewRow.Item("Name") = DB.ds_A.Tables("A_Data").Rows(0).Item(0)
		dsNewRow.Item("1") = DB.ds_A.Tables("A_Data").Rows(0).Item(1)
		dsNewRow.Item("2") = DB.ds_A.Tables("A_Data").Rows(0).Item(2)


DB.ds_B.Tables("B_Data").Rows.Add(dsNewRow)


DB.da_B.Update(DB.ds_B, "B_Data")
DB.ds_B.AcceptChanges()

Since this is a copy from one dataset to another, I would like to simplify the code some... So, this is what I have so far

VB.NET:
Expand Collapse Copy
Dim cb As New OleDb.OleDbCommandBuilder(DB.da_B) 

DB.ds_B = DB.ds_A.Copy

DB.da_B.Update(DB.ds_B, "B_Data")
DB.ds_B.AcceptChanges()

The copy works, I can access the data in the DB.ds_B dataset just fine after that command. However I believe I'm missing something, as the Update code doesn't actually update the database with the new information (no errors or anything)....

Could anyone please point me in the right direction?

Thanks
 
I think a 'BindingSource' Object would be useful.

VB.NET:
Expand Collapse Copy
Dim bs as New BindingSource(DB.ds_B, "B_Data")

Then before you call your update commands do this:

VB.NET:
Expand Collapse Copy
bs.EndEdit

Hope this one helps.

Jah Bless!!!:D
 
I'm not sure if it is because I'm using .NET framework 1.0 or what, but it doesn't recognize the BindingSource type. Besides, why would it work one way without it and one way without it?

I don't 'think' it is the database connection.
VB.NET:
Expand Collapse Copy
DB.con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = " & MyPath & "/B.mdb"
I could be wrong, but just the way things appear to me. I think it has to do with the way I'm copying the data.



If I check
VB.NET:
Expand Collapse Copy
DB.ds_B.HasChanges()
after I do the copy it returns false.

I tried to do
VB.NET:
Expand Collapse Copy
DB.ds_B.Merge(DB.ds_A, True)
instead, but again, the dataset updates with the correct information, however it doesn't recognize that their are changes to be updated.
:confused:

Thanks
 
I think DB.ds_B.HasChanges() will really return false because you only copied the data and everything into another dataset.

Can you post your dataAdapter code?

Jah Bless!!!
 
Oh man. redm I think the best solution would be to migrate to the latest .NET Framework version.

I hope it won't be hard on your part.:D
 
You never answered this question:

Can I jsut ask you.. Why are you doing this?

Quite often, the problem is not with the problem, but with the imagined solution to the problem. We only know what youre doing. If we knew why you were doing it, we could perhaps tell you a way that would work
 
Back
Top