Exception in Add Parameter To DbCommand

As you are using System.Data.OleDb as database provider ( regardless you are using a sql server ) you need to use the ? as the parameter placeholder like:

"UPDATE [Student] SET Name = ? Where Id = ?";

By using the System.Data.OleDbprovider the names of the parameters doesn`t matter anymore but you need to ensure that the occurance of the parameters match the order the parameterobjects are added to the command objects parameter collection.

EDIT: If you want to keep the @ as parameter placeholder you can just change this:

DbProviderFactory dbFactory = DbProviderFactories.GetFactory("System.Data.OleDb");

to

DbProviderFactory dbFactory = DbProviderFactories.GetFactory("System.Data.SqlClient");

Tags:

C#

Sql

Ado.Net