I am facing some problem in updating ms access with parameters.
I succeeded to insert the data in access with parameters.
My code for inserting the data is:
Dim dbPath As String = "C:\Users\Abhishek\Documents\ToolDatabase.mdb"
Dim connStr As String ="Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & dbPath & ";Jet OLEDB:Database Password=agupt80;"
Using connection As New OleDb.OleDbConnection(connStr)
Dim cmd As New OleDb.OleDbCommand
Dim trans As OleDb.OleDbTransaction
If (connection.State = ConnectionState.Closed) Then
connection.Open() 'Open connection to database
End If
cmd.Connection = connection
trans = connection.BeginTransaction(IsolationLevel.ReadCommitted)
cmd.Transaction = trans
cmd.CommandText = "insert into Table1 (Topic, Client, Carrier) values(@Topic, @Client, @Carrier)"
With cmd
.Parameters.AddWithValue("@Topic", Me.TextBox1.Text)
.Parameters.AddWithValue("@Client", Me.TextBox2.Text)
.Parameters.AddWithValue("@Carrier", Me.TextBox3.Text)
.ExecuteNonQuery() 'Execute command
End With
trans.Commit() 'Save record
MessageBox.Show("Record Saved", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Using
And my code for updating the Access is:
strsql = "UPDATE Table1 SET Topic ='" & TextBox1.Text & "'," _
& "Client ='" & TextBox2.Text & "'," _
& "Carrier = '" & TextBox3.Text & "'"
& "where Topic = '" & ComboBox1.Text & "'"
Dim acscmdup As New OleDb.OleDbCommand()
acscmdup.CommandText = strsql
If (con.State = ConnectionState.Closed) Then
con.Open()
End If
acscmdup.Connection = con
acscmdup.ExecuteNonQuery()
acscmdup.Dispose()
MessageBox.Show("Database Updated", "Updated..", MessageBoxButtons.OK, MessageBoxIcon.Information)
con.Close()
Please tell me the code to update access with passing parameters.
Your response would be appreciated.