I'm trying to update an Access database by using an OLE connection, retrieving the information from textboxes where the user enters the new information.

All the fields in my Access table are required fields, so I have validated that some info is entered in each one of the textboxes and that is the correct data type.

But when I run the update query I get an error message saying something like values haven't been entered for some required parameters (my Visual Studio is the Spanish version, so I can't give the exact error message in English).

The bit of code where the error occurs is inside the procedure called by my "Ok" button:

Dim campo1, campo2, campo3, campo4, campo5 As String
        Dim campo6, campo7, campo8 As Double
        Dim campo9, campo10 As Integer

        campo1 = Trim(TextBox1.Text)
        campo2 = Trim(TextBox2.Text)
        campo3 = Trim(TextBox3.Text)
        campo4 = Trim(TextBox4.Text)
        campo5 = Trim(TextBox5.Text)
        campo6 = CDbl(Trim(TextBox6.Text))
        campo7 = CDbl(Trim(TextBox7.Text))
        campo8 = campo6 + ((campo6 * campo7) / 100)
        campo9 = CInt(Trim(TextBox9.Text))
        campo10 = CInt(Trim(TextBox10.Text))


        Dim aCommand As OleDbCommand

        aCommand = New OleDbCommand("update stock set idProducto = campo1, nombreproducto = campo2, proveedor = campo3, categoria = campo4, unidad = campo5, preciocosto = campo6, remarcar = campo7, precioventa = campo8, stock = campo9,  stockmin_unid = campo10 where idProducto like " + id, aConnection)

(I didn't post the whole code inside the procedure, but of course I'm creating the connection and everything)

The table has 10 fields, and the data is read from the textboxes and stored in variables (campo1, campo2, campo3, etc.), which I'm then using in the "set" query command.

"id" is the first field from the selected row in the datagrid, which I'm sending as a parameter to the procedure called by the "OK" button.


The error message shows at runtime, so I'm guessing it's something in the query. Am I writing it correctly?


Thanks!!

Recommended Answers

All 2 Replies

you are passing something wrong in command and update query.try this

"update stock set idProducto =" & campo1 & ", nombreproducto =" & campo2 & ", proveedor =" & campo3 & ", categoria =" & campo4 & ", unidad = " & campo5 & ", preciocosto =" & campo6 & ", remarcar =" & campo7 & ", precioventa =" & campo8 & ", stock =" & campo9 & ",  stockmin_unid = " & campo10 & " where idProducto like '" &  id & "%'"

then pass to your command

Hi,

If it it still does not work, a good tip when working in Access is to use the QBE to generate the SQL for your query, that way you know the syntax is correct for Access.

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.