Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update dataset?

Status
Not open for further replies.

Vandy02

Programmer
Jan 7, 2003
151
US
I have Form1 with a datagrid of Employees table..
I have a button on this form that will open a another form (frmEditDetail) where I can edit the data by passing the current position of the CurrencyManager. The data passes, but I do not know how to save changes to the dataset...
Can anyone help me...?
I was planning on using the SaveEdit()
-------------------------------------------------------
--Form1--
-------------------------------------------------------Public Class Form1
Inherits System.Windows.Forms.Form
Dim bm As BindingManagerBase
Dim cm As CurrencyManager
Dim dr As DataRow
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OleDbDataAdapter1.Fill(DataSet11, "Employees")
bm = Me.BindingContext(DataSet11, "Employees")
End Sub

Private Sub DataGrid1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Click
' Get the Currency Manager by using the BindingContext of the DataGrid
cm = CType(Me.BindingContext(DataGrid1.DataSource, DataGrid1.DataMember), CurrencyManager)

' Retrieve the default DataView of the DataGrid
Dim dv As DataView = CType(cm.List, DataView)

' Use Currency Manager and DataView to retrieve the Current Row
'Dim dr As DataRow
dr = dv.Item(cm.Position).Row
'MessageBox.Show(dr.ToString())
' Display the Current Row Data
TextBox1.Text = dr(0).ToString
TextBox2.Text = dr(1).ToString
TextBox3.Text = dr(2).ToString
End Sub

Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
Dim frmEditDetail As New frmEditDetail
frmEditDetail.EditDetail(cm)
frmEditDetail.Show()
frmEditDetail.Dispose()
End Sub
End Class
-------------------------------------------------------
--frmEditDetail--
-------------------------------------------------------
Public Class frmEditDetail
Inherits System.Windows.Forms.Form
Dim drvDetail As DataRowView
Dim vueDetail As DataView

Public Sub EditDetail(ByVal cm As CurrencyManager)
drvDetail = CType(cm.Current, DataRowView)
vueDetail = drvDetail.DataView
Dim dr As DataRow

Me.BindingContext(vueDetail).Position = cm.Position
txtEmployeeID.DataBindings.Add("Text", vueDetail, "EmployeeID")
txtFirstName.DataBindings.Add("Text", vueDetail, "FirstName")
txtLastName.DataBindings.Add("Text", vueDetail, "LastName")

If Me.ShowDialog = DialogResult.OK Then
cm.EndCurrentEdit()
Else
cm.CancelCurrentEdit()
End If
End Sub
Private Sub frmEditDetail_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Call SaveEdit()
End Sub
Private Sub SaveEdit()

End Sub

End Class
-------------------------------------------------------

Thanks...
 
you should do a oledbdataadapter.update(DataSet11, "Employees")

and a cm.endcurrentedit just before that.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top