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