Inexplicable sqlserver update error: oledbexception must declare a scalar variable

Source: Internet
Author: User

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 ??

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.