Hey everyone. I'm trying to get this form setup to where a user can edit a selected row in a datagrid. I have it setup where the user can double click on the row, and it populates the information for them to edit, but it is adding a new row. I'm not sure how to get it to just edit the selected row. Right now, I'm just updating the data adapter, as I'm not wanting to mess up the database.
Here is the code for the btnUpdate:
Any help would be much appreciated. Thanks!
Here is the code for the btnUpdate:
VB.NET:
con3.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = profees.mdb"
con3.Open()
sql3 = "Select * From tblTrans where ID = " & txtTransID.Text
da3 = New OleDb.OleDbDataAdapter(sql3, con3)
da3.Fill(ds3, "Changes")
con3.Close()
MaxRows = ds3.Tables("Changes").Rows.Count ' Stores how many rows are in the DataSet
inc = MaxRows
Dim cb As New OleDb.OleDbCommandBuilder(da3) ' Command Builder
Dim dsNewRow As DataRow ' DataRow Object - needed for adding new rows to DataSet
dsNewRow = ds3.Tables("Changes").NewRow() ' Creates the new DataRow object, stores it in dsNewRow variable
' Update the Dataset
dsNewRow.Item("ID") = txtTransID.Text
dsNewRow.Item("Post") = dtpPost.Value
dsNewRow.Item("DOS") = dtpDOS.Value
dsNewRow.Item("Account") = txtPat.Text
dsNewRow.Item("Charge") = txtCharge.Text
dsNewRow.Item("Insurance") = cboInsurance.Text
dsNewRow.Item("Physician") = cboPhysician.Text
ds3.Tables("Changes").Rows.Add(dsNewRow) ' This method adds the Row to the DataSet
da3.Update(ds3, "Changes") ' DataAdapter update
End Sub
Any help would be much appreciated. Thanks!