I'm new here and to VB.net. I'm sure this is simple and I appologize.
I have a windows form that contains a DataGridView that is bound to a Dataset Table. There are also several textboxes that are also bound to fields in the dataset table. There is a button to save changes. The Datagridview is set to read only.
My problem is, if I edit the record through the textboxes and want to save the changes. I have to click on another record in the datagridview for the changes to be saved correctly. If I do not click on a different row then the dataset.HasChanges = false and no changes will be saved.
I've tried refreshing the datagridview and that populates the values from the textboxes into the datagrid, but it does not put them in the dataset.
Thanks for any help anyone can provide.
I have a windows form that contains a DataGridView that is bound to a Dataset Table. There are also several textboxes that are also bound to fields in the dataset table. There is a button to save changes. The Datagridview is set to read only.
My problem is, if I edit the record through the textboxes and want to save the changes. I have to click on another record in the datagridview for the changes to be saved correctly. If I do not click on a different row then the dataset.HasChanges = false and no changes will be saved.
I've tried refreshing the datagridview and that populates the values from the textboxes into the datagrid, but it does not put them in the dataset.
Thanks for any help anyone can provide.
VB.NET:
Private Sub FrmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim DBLogin As String = "Data Source=" & DB_DSN & ";User Id=" & UN & ";Password=" & PW & ";"
conn = New OracleConnection(DBLogin)
DAReports = New OracleDataAdapter("select * from rptmgr_reports", conn)
DAReports.Fill(ds, "RPTMGR_REPORTS")
DAContacts = New OracleDataAdapter("select * from rptmgr_contacts", conn)
DAContacts.Fill(ds, "RPTMGR_CONTACTS")
DataGridReports.DataSource = ds.Tables(0)
DataGridRecipients.DataSource = ds.Tables(1)
ds.Tables(1).Columns(0).Unique = True
ds.Tables(1).Columns(0).AutoIncrement = True
ds.Tables(1).Columns(0).AutoIncrementSeed = _
If(IsDBNull(ds.Tables(1).Compute("Max(ID)", Nothing)) _
, 20001, ds.Tables(1).Compute("Max(ID)", Nothing) + 1)
TxtBoxOrg.DataBindings.Add("text", ds.Tables(1), "ORGANIZATION")
TxtBoxName.DataBindings.Add("text", ds.Tables(1), "NAME")
TxtBoxEmail.DataBindings.Add("text", ds.Tables(1), "EMAIL")
MTxtBoxPhone.DataBindings.Add("text", ds.Tables(1), "PHONE")
MTxtBoxAltPhone.DataBindings.Add("text", ds.Tables(1), "ALTPHONE")
Dim CBItems As ArrayList = New ArrayList()
CBItems.Add(New cValue("Active", "A"))
CBItems.Add(New cValue("Inactive", "I"))
ComboBoxStatus.DataSource = CBItems
ComboBoxStatus.DisplayMember = "Display"
ComboBoxStatus.ValueMember = "Value"
ComboBoxStatus.DataBindings.Add("SelectedValue", ds.Tables(1), "Status")
End Sub
Private Sub ButSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButSave.Click
DataGridRecipients.Refresh()
If ds.HasChanges.ToString() = False Then
MsgBox("There are no changes to be made at this time")
Else
Try
MessageBox.Show(DAContacts.UpdateCommand.CommandText)
DAContacts.Update(ds, "RPTMGR_CONTACTS")
MsgBox("Database updated successfully")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub
Last edited: