--TripWire--
asked on
Saving record in VB2010
Hello,
I have a backend database as my bindingsource, and am attempting to use a Save command button to reflect the changes on my form into my database. Please advise.
Thank you.
I have a backend database as my bindingsource, and am attempting to use a Save command button to reflect the changes on my form into my database. Please advise.
Thank you.
Option Explicit On
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Windows.Forms.DataGridView
Public Class frmInput
Dim sqlString As String = "SELECT * FROM tblInsuranceClaim"
Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\Administrator\Desktop\MyDBBackend.mdb;User ID=admin"
Dim OleDBConn1 As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(ConnString)
Dim OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(sqlString, OleDBConn1)
Dim dbGen As New OleDbCommandBuilder(OleDbDataAdapter1)
Private Sub frmOrder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'MyDBBackendDataSet3.tblInsuranceClaim' table. You can move, or remove it, as needed.
Me.TblInsuranceClaimTableAdapter.Fill(Me.MyDBBackendDataSet.tblInsuranceClaim)
txtPDrug.Text = frmDrugs.txtDrugHidden.Text
Try
OleDbDataAdapter1.AcceptChangesDuringUpdate = True
Catch ex As Exception
MsgBox("An exception was thrown because the back-end database is currently not allowing updates. Please try again.")
End Try
Try
OleDBConn1.Open()
Catch ex As Exception
MsgBox("An exception was thrown because a connection to the database or database tables cannot be established")
End Try
TblInsuranceClaimBindingSource.AddNew()
End Sub
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
Try
Me.Validate()
Me.TblInsuranceClaimBindingSource.EndEdit()
OleDbDataAdapter1.Update(Me.MyDBBackendDataSet.tblInsuranceClaim)
MyDBBackendDataSet.Tables("tblInsuranceClaim").AcceptChanges()
OleDbDataAdapter1.Update(MyDBBackendDataSet, "tblInsuranceClaim")
OleDBConn1.Close()
MsgBox("Update Successful")
Catch ex As Exception
MsgBox("Update Failed")
End Try
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hmm...Well, I already have the adapter.update method in my code above
ASKER
It was helpful, but I wasn't able to find a full solution this way. But thank you.
ASKER
My form has a number of different controls on it, mostly textboxes. And I want the information that the user types in to be saved into the database when the user clicks the Save command button on the form.