Help with datagrid updating example...

P

Paul M

hi there,

this is the source code i use to populate a dataset, bind it and perform the
update on any changes made to the datagrid.

Only problem is when i try the update, it does not save back to the
database....
any help is appreciated....thanks,
Paul.

Private ds As DataSet
sSQL = "SELECT * FROM [tblUser]"
..............
..............'BIND THE DATAGRID WITH TABLE DATA...works fine.
With dgTable
.CaptionText = SourceName
ds = CreateDataSet(sSQL, tableName)
.DataSource = ds.Tables(0)
End With
...............
...............

Function CreateDataSet(ByVal sql As String, ByVal tablename As String) As
DataSet
Dim da As OleDbDataAdapter
Try
cmd = New OleDbCommand
cmd.CommandText = sql
cmd.Connection = conn
da = New OleDbDataAdapter(cmd)
ds = New DataSet(tablename)
da.Fill(ds)
CreateDataSet = ds
Catch ex As Exception
CreateDataSet = Nothing
Finally
da.Dispose()
da = Nothing
End Try
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
ds.GetChanges()
ds.AcceptChanges()
Catch ex As Exception
MessageBox.Show(ex.Message, "Save Changes", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
End Try
End Sub
 
P

Paul M

actually, yes in my latest code, after the AcceptChanges method, i have the
following:

da.Update(ds)

but it still doesnt save to the database???

Paul.

Uri Dor said:
DataAdapter has an Update method. I suggest you look it up

Paul said:
hi there,

this is the source code i use to populate a dataset, bind it and perform the
update on any changes made to the datagrid.

Only problem is when i try the update, it does not save back to the
database....
any help is appreciated....thanks,
Paul.

Private ds As DataSet
sSQL = "SELECT * FROM [tblUser]"
.............
.............'BIND THE DATAGRID WITH TABLE DATA...works fine.
With dgTable
.CaptionText = SourceName
ds = CreateDataSet(sSQL, tableName)
.DataSource = ds.Tables(0)
End With
..............
..............

Function CreateDataSet(ByVal sql As String, ByVal tablename As String) As
DataSet
Dim da As OleDbDataAdapter
Try
cmd = New OleDbCommand
cmd.CommandText = sql
cmd.Connection = conn
da = New OleDbDataAdapter(cmd)
ds = New DataSet(tablename)
da.Fill(ds)
CreateDataSet = ds
Catch ex As Exception
CreateDataSet = Nothing
Finally
da.Dispose()
da = Nothing
End Try
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
ds.GetChanges()
ds.AcceptChanges()
Catch ex As Exception
MessageBox.Show(ex.Message, "Save Changes", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
End Try
End Sub
 
V

vijai thoppae

I guess you need to specify the table name while calling update.
da.update(ds,"table name");

~Vijai
Paul M said:
actually, yes in my latest code, after the AcceptChanges method, i have the
following:

da.Update(ds)

but it still doesnt save to the database???

Paul.

Uri Dor said:
DataAdapter has an Update method. I suggest you look it up
perform
the
update on any changes made to the datagrid.

Only problem is when i try the update, it does not save back to the
database....
any help is appreciated....thanks,
Paul.

Private ds As DataSet
sSQL = "SELECT * FROM [tblUser]"
.............
.............'BIND THE DATAGRID WITH TABLE DATA...works fine.
With dgTable
.CaptionText = SourceName
ds = CreateDataSet(sSQL, tableName)
.DataSource = ds.Tables(0)
End With
..............
..............

Function CreateDataSet(ByVal sql As String, ByVal tablename As String) As
DataSet
Dim da As OleDbDataAdapter
Try
cmd = New OleDbCommand
cmd.CommandText = sql
cmd.Connection = conn
da = New OleDbDataAdapter(cmd)
ds = New DataSet(tablename)
da.Fill(ds)
CreateDataSet = ds
Catch ex As Exception
CreateDataSet = Nothing
Finally
da.Dispose()
da = Nothing
End Try
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
ds.GetChanges()
ds.AcceptChanges()
Catch ex As Exception
MessageBox.Show(ex.Message, "Save Changes", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
End Try
End Sub
 
P

Paul Delcogliano

Call the Update method before the call to AcceptChanges.

Paul


Paul M said:
actually, yes in my latest code, after the AcceptChanges method, i have the
following:

da.Update(ds)

but it still doesnt save to the database???

Paul.

Uri Dor said:
DataAdapter has an Update method. I suggest you look it up
perform
the
update on any changes made to the datagrid.

Only problem is when i try the update, it does not save back to the
database....
any help is appreciated....thanks,
Paul.

Private ds As DataSet
sSQL = "SELECT * FROM [tblUser]"
.............
.............'BIND THE DATAGRID WITH TABLE DATA...works fine.
With dgTable
.CaptionText = SourceName
ds = CreateDataSet(sSQL, tableName)
.DataSource = ds.Tables(0)
End With
..............
..............

Function CreateDataSet(ByVal sql As String, ByVal tablename As String) As
DataSet
Dim da As OleDbDataAdapter
Try
cmd = New OleDbCommand
cmd.CommandText = sql
cmd.Connection = conn
da = New OleDbDataAdapter(cmd)
ds = New DataSet(tablename)
da.Fill(ds)
CreateDataSet = ds
Catch ex As Exception
CreateDataSet = Nothing
Finally
da.Dispose()
da = Nothing
End Try
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
ds.GetChanges()
ds.AcceptChanges()
Catch ex As Exception
MessageBox.Show(ex.Message, "Save Changes", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
End Try
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top