标签:class 获取 取数据 value temp end build 参考 dep
1 问题概述
在DAL层,通过标量给变量赋值时,出现如下异常
我们来看看在数据访问层的SQL语句:
//根据EmployeeName条件获取数据 public DataTable GetEmployeeToTable(string EmployeeName) { StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT EmployeeID,EmployeeName,EmployeeMajor, EmployeeDepartment,EmployeeTel,EmployeeEmail, EmployeeJiGuan,EmployeeAddress,EmployeePosition,EmployeeBirthday "); strSql.Append(" WHERE EmployeeName=@EmployeeName "); SqlParameter[] parameters = { new SqlParameter("@EmployeeName",SqlDbType.VarChar,50) }; parameters[0].Value = EmployeeName; return DbHelperSQL.GetDataTable(strSql.ToString()); }
2 问题分析与解决
2.1 问题分析
变量参数未传递进去
2.2 问题解决
将参数传递进去即可
1 public DataTable GetEmployeeToTable(string EmployeeName) 2 { 3 StringBuilder strSql = new StringBuilder(); 4 strSql.Append("SELECT EmployeeID,EmployeeName,EmployeeMajor, EmployeeDepartment,EmployeeTel,EmployeeEmail, EmployeeJiGuan,EmployeeAddress,EmployeePosition,EmployeeBirthday "); 5 strSql.Append(" WHERE EmployeeName=@EmployeeName "); 6 SqlParameter[] parameters = { 7 new SqlParameter("@EmployeeName",SqlDbType.VarChar,50) 8 }; 9 parameters[0].Value = EmployeeName; 10 return DbHelperSQL.Query(strSql.ToString(), parameters).Tables[0]; 11 }
3 版权
标签:class 获取 取数据 value temp end build 参考 dep
原文地址:http://www.cnblogs.com/wangjiming/p/7615618.html