"SQL Server" problem collection must declare a scalar variable

Source: Internet
Author: User
Tags scalar

Tag: Class gets fetch data value temp End build reference dep

1 Overview of issues

In the DAL layer, the following exception occurs when assigning a value to a variable by a scalar

Let's take a look at the SQL statements in the data access layer:

//get data based on employeename conditions         PublicDataTable getemployeetotable (stringEmployeeName) {StringBuilder strSQL=NewStringBuilder (); Strsql.append ("SELECT employeeid,employeename,employeemajor, Employeedepartment,employeetel,employeeemail, EmployeeJiGuan, Employeeaddress,employeeposition,employeebirthday"); Strsql.append ("WHERE [email protected]"); sqlparameter[] Parameters= {                    NewSqlParameter ("@EmployeeName", SqlDbType.VarChar, -)            }; parameters[0]. Value =EmployeeName; returndbhelpersql.getdatatable (strsql.tostring ()); }

2 Problem Analysis and solution

2.1 Problem Analysis

Variable parameter not passed in

2.2 Problem Solving

Pass in the parameters

1  PublicDataTable getemployeetotable (stringEmployeeName)2         {3StringBuilder strSQL =NewStringBuilder ();4Strsql.append ("SELECT employeeid,employeename,employeemajor, Employeedepartment,employeetel,employeeemail, EmployeeJiGuan, Employeeaddress,employeeposition,employeebirthday");5Strsql.append ("WHERE [email protected]");6sqlparameter[] Parameters = {7                     NewSqlParameter ("@EmployeeName", SqlDbType.VarChar, -)8             };9parameters[0]. Value =EmployeeName;Ten             returnDbhelpersql.query (Strsql.tostring (), parameters). tables[0]; One}

3 Copyrights

    • Thank you for your reading, if there are shortcomings, welcome advice, common learning and common progress.
    • Bo main website: http://www.cnblogs.com/wangjiming/.
    • A very small number of articles using reading, reference, reference, copying, copying and pasting into a variety of ways, most of the original.
    • If you like, please recommend, if you have new ideas, welcome, email: [Email protected].
    • The blog can be reproduced, but must be well-known from the blog source.

"SQL Server" problem collection must declare a scalar variable

Related Article

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.