I try to solve this problem:
when i add, delete record it working, but for update is not working
please someone help me here code:

Private Sub UpdateRecord()
VarTransaction = VarConn.BeginTransaction

Dim VarOleDbCommand As New OleDbCommand
Dim VarStringBuilder As StringBuilder

VarStringBuilder = New StringBuilder


VarStringBuilder.Append("UPDATE tblCl_TrainingType")
VarStringBuilder.Append(" SET Type_title=@Type_title,Clarification=@Clarification")
VarStringBuilder.Append(" WHERE (Training_typeID=@Training_typeID)")

Dim SqlUpdate As String
SqlUpdate = VarStringBuilder.ToString


If MessageBox.Show("Do you want to update this record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then

With VarOleDbCommand
.CommandText = SqlUpdate
.CommandType = CommandType.Text
.Connection = VarConn
.Transaction = VarTransaction
.Parameters.Clear()
.Parameters.Add("@Training_typeID", OleDbType.VarChar).Value = txtID.Text
.Parameters.Add("@Type_title", OleDbType.VarChar).Value = txtTrainingTitle.Text.Trim
.Parameters.Add("@Clarification", OleDbType.VarChar).Value = txtClarification.Text.Trim

Dim Result As Integer
Result = .ExecuteNonQuery()

If Result = 0 Then
VarTransaction.Rollback()
MessageBox.Show("Record Update Failed!", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtTrainingTitle.SelectAll()
Else
VarTransaction.Commit()
MessageBox.Show("Record has been updated!", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information)

VarTransaction.Commit()

DataLoad()

DataGridCondition()

DataGridViewFormat()

FormLoadCondition()
End If
End With

End If

End Sub

You need to open the Connection before this line--Result = .ExecuteNonQuery()

and close it after VarTransaction.Commit().

Without an Open Connection, the Command cannot Execute.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.