I used to update the database using oledbdataadapter. Today I tried to update the database using oledbcommand.
Stage: SQL Server 2005
Use the following code:
String strsql = "Update m_employee set employeename = @ employeename where employeeid = @ employeeid ";
Using (oledbcommand comm = new oledbcommand (strsql, olecn ))
{
Comm. Parameters. Add (New oledbparameter ("@ employeename", oledbtype. varchar). value = "DDD ";
Comm. Parameters. Add (New oledbparameter ("@ employeeid", oledbtype. varchar). value = employeeid;
Comm. executenonquery ();
}
Always reported error: must declare the scalar variable @ employeename
I have been debugging for N hours.
After changing the following method, we can use string strsql = "Update m_employee set employeename =? Where employeeid =? ";
Using (oledbcommand comm = new oledbcommand (strsql, olecn ))
{
Comm. Parameters. Add (New oledbparameter ("@ p1", oledbtype. varchar). value = "DDD ";
Comm. Parameters. Add (New oledbparameter ("@ p2", oledbtype. varchar). value = employeeid;
Comm. executenonquery ();
}
I don't understand why. Is there a problem with my code or oledb ??