问题描述
Hiii,
我想在sql数据适配器中传递参数我试试这个
string cmdstr =select * from Report where InstituteId = @InstituteId;
SqlDataAdapter adp = new SqlDataAdapter(cmdstr,con);
adp.SelectCommand.Parameters.Add(@ InstituteId,Session [InstituteId]);
但是我得到错误参数化查询'(@InstituteId nvarchar(4000))需要参数'@InstituteId',这是未提供的。
Hiii,
I want to pass parameter in sql data adapter i try this
string cmdstr = "select * from Report where InstituteId=@InstituteId";
SqlDataAdapter adp = new SqlDataAdapter(cmdstr, con);
adp.SelectCommand.Parameters.Add("@InstituteId", Session["InstituteId"]);
But im getting error The parameterized query '(@InstituteId nvarchar(4000)) expects the parameter '@InstituteId', which was not supplied.
推荐答案
string cmdstr = "select * from Report where InstituteId=@InstituteId";
Sqlcommand cmd=new SqlCommand(cmdstr,con);
cmd.Parameter.add(new SqlParameter("@InstituteId", Session["InstituteId"].toString());
SqlDataAdapter adp = new SqlDataAdapter(cmd);
Datatable dt=new Datatable();
adap.fill(dt);
//adp.SelectCommand.Parameters.Add("@InstituteId", Session["InstituteId"]);
string paramValue = (string)Session["InstituteId"]; //Unbox the value from the session cache!
adp.SelectCommand.Parameters.Add("@InstituteId",SqlDbType.NVarChar, 40, (paramValue == null ? DBNull.Value : paramValue)); //Specify the type and length of the parameter!
这篇关于如何将参数传递给Sql Data Adapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!