Quantcast
Channel: VBForums - Database Development
Viewing all articles
Browse latest Browse all 2918

Database Updating using SQL update with Parameters

$
0
0
Hi,
I 'am trying to Update a MS Access database using visual Basic.net
and the SQL Update Statement and a textbox. to display my data Iam using a
DataGridview. the problem is when I update my data I can see
the changes made to my data grid but on the database.
here is the code that I 'am using.


Code:

    Private Sub btnSave_Click(sender As System. Object, e As System. EventArgs) Handles btnSave.Click
        If btnEdit.Enabled = False Then

            If Not MiConexion.State = ConnectionState.Open Then
                'open connection if it is not yet open
                MiConexion.Open()

            End If
            Dim query As String


            query = "UPDATE TRUNK_INVENTORY SET Part_Number=?" & "WHERE Part_Number=?"
            Dim cmd As OleDbCommand = New OleDbCommand(query, MiConexion)
            cmd.Parameters.AddWithValue("Description ", txtDescription.Text)
            cmd.Parameters.AddWithValue("Analyzer ", txtAnalyzer.Text)
            cmd.Parameters.AddWithValue("Trunk_Location ", txtTrunLocation.Text)
            Try
                cmd.ExecuteNonQuery()
            Catch ex As Exception
                MessageBox.Show(ex.Message & " - " & ex.Source)
            End Try
end sub


Viewing all articles
Browse latest Browse all 2918

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>