sp_executesql 执行报错
string sql = " N 'select p_cid, " +
"p_bmaster from t_person " +
" where p_cid=@p_cid ' ";
string para = " N '@p_cid varchar(40) ' ";
string condition = " @p_cid= '0102 ' ";
SqlParameter par1 = new SqlParameter( "@stmt ", sql);
SqlParameter par2 = new SqlParameter( "@params ", para);
SqlParameter par3 = new SqlParameter( "@param1 ", condition);
SqlParameter[] pars = { par1, par2,par3 };
ExecuteSqlDtr(CommandType.StoredProcedure, "sp_executesql ", pars);
ExecuteSqlDtr为一个执行sql的函数,总是报@p_cid varchar(40)语法错误
------解决方案--------------------SQL参数名用:@p_cid别用变量了。
------解决方案--------------------直接使用
ExecuteSqlDtr(CommandType.Text, sql, new SqlParamater( "@p_cid ", "0102 "));
不就行了迈?
SQL SErver 引擎自己调用 sp_executeSql
------解决方案--------------------楼主,我觉得你这段代码根本没必要用sp_ExecuteSql,就用普通的参数执行就可以了