471,093 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,093 software developers and data experts.

DataGrid / Dataset / DataAdaptor / DataBase updat problem - please

My dataset is not updating my database after the user modifies the datagrid.
I populate my data with the load sub below.
In the Save Sub (below), I have generated my DataSet 'dataSet11' from my
DataAdaptor 'SqlDataAdapter1' and the DataConnection 'SqlConnection1' and
they all seem to be connected correctly. But my data does not update.
the dataAdaptor is configured for Insert/Update/delete and the datagrid
datasource is DataSet11.TableName. Any ideas?

Private Sub Thresholds_Load(ByVal sender As.....
Try
cn = New SqlClient.SqlConnection("user id=" & UserName.Text & ";password="
& Password.Text & ";database=" & Database.Text & ";server=" & Server.Text)
cn.Open()
cmdSelect.Connection = cn

Dim da As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("Select
* from MISRE_Threshold", cn)
Dim dsThreshold As DataSet = New DataSet

' fill dataset
da.Fill(dsThreshold, "MISRE_Threshold")

'Attach DataSet to DataGrid
dgThreshold.DataSource = dsThreshold.DefaultViewManager

Catch ex As Exception
MessageBox.Show("Error: Could not establish database connection")
End Try
Private Sub btnSave_Click(ByVal sender.....

SqlDataAdapter1.Update(DataSet11)

EndSub

May 15 '06 #1
1 1131
If you're using the VB IDE to create the code that connects to your
database, you may be running into the "local copy" issue. The "Create
New Connection" wizard pops up a messagebox that says something like
"There is no local copy of the database you're connecting to, do you
want to create one and copy the data to it?" The default is "Yes".

Taking the default will mean that the updates your program makes to the
database only update the local copy. While you're executing the
program, you'll see the changes, but if you do a "Save", those changes
are only saved to the local copy. In addition, the next time your
program executes, a fresh copy of the database overlays your local
copy, wiping out any changes you may have made previously.

If this is what's causing your problem, you could either specify "no
local copy" when the wizard creates the connection code, or copy your
local copy of the database (which will be in your Projects folder) over
the original database data after your program executes.

May 15 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Calvin KD | last post: by
17 posts views Thread by Mike Fellows | last post: by
16 posts views Thread by Geoff Jones | last post: by
2 posts views Thread by Brahm | last post: by
4 posts views Thread by m - team1 via DotNetMonster.com | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.