Answered by:

No value given for one or more required parameters in C# while using OLEDB command for update query

Question

This is Srikanth,I'm a new comer to this msdn and my task is to update and delete rows in the ms access data base using C#.
But there is an error showing "No value given for one or more required parameters."
whle running update query.

Keep in mind that with OleDb, parameters are positional, not named. You can name your parameters, but you cannot use the @ syntax in your command (it throws an error about needing to declare a scalar variable) ... the correct syntax is to use the ? ... and
it will take the parameters in the order in which you've added them.

Also, I prefer the .AddWithValue syntax, which is even more readable, I think.

All replies

1st of all, you should try to learn using Parametrized query. Now you pass values directly in the query statements, using parametrized query gives you a better control over the code, and it a way better looking.

But anyway, even this code of yours should work fine. Can I ask you, if all the column in your dataBase`s table as type of varchar (string)? Because you pass to all of then a Text property, which is type of stirng.

So if you have any column for example type of integer (int), you have to convert the data passed to the database, for example., lets say "sal" is type of decimal:

Keep in mind that with OleDb, parameters are positional, not named. You can name your parameters, but you cannot use the @ syntax in your command (it throws an error about needing to declare a scalar variable) ... the correct syntax is to use the ? ... and
it will take the parameters in the order in which you've added them.

Also, I prefer the .AddWithValue syntax, which is even more readable, I think.