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.

Recommended Answers

What error you got? pls post the error ....

Jump to Post

All 4 Replies

What error you got? pls post the error ....

please always ask to the point question , this will make easy to others to help you , now tell me the basic prob you are facing . so that i can better answer your prob.

Regards

I got my problem solved.
There was not any error, i just want to update the access by passing parameters.
Atlast i succeeded. Thank you guys for responding. :)

please mark this thread solved.

Be a part of the DaniWeb community

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