[求助]URL传值,@id接收问题..
接收URL传过来的id值,然后在存储过程里使用它. 现在出现错误:过程 'showrestore ' 需要参数 '@id ',但未提供该参数..
恳请各位大佬帮我看看到底哪错了?
protected void Page_Load()
{
SqlConnection SqlConnection1 = new SqlConnection( ".. ");
string sid = Request.QueryString[ "id "].ToString();
SqlCommand cmd = new SqlCommand( "showrestore ", SqlConnection1);
SqlConnection1.Open();
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter p1 = new SqlParameter( "@id ", SqlDbType.Int);
p1.Value = Convert.ToInt32(sid);
cmd.Parameters.Add(p1);
cmd.ExecuteNonQuery();
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter( "showrestore ", SqlConnection1);
DataSet DataSet1 = new DataSet();
SqlDataAdapter1.Fill(DataSet1);
DataGrid1.DataSource = DataSet1.Tables[0].DefaultView;
DataGrid1.DataBind();
}
请多指教..
[解决办法]
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter( "showrestore ", SqlConnection1);
DataSet DataSet1 = new DataSet();
SqlDataAdapter1.Fill(DataSet1);
DataGrid1.DataSource = DataSet1.Tables[0].DefaultView;
DataGrid1.DataBind();
没有添加参数啊
[解决办法]
SqlParameter[] parameters = {
new SqlParameter( "@InfoTypeName ", SqlDbType.VarChar,100),
new SqlParameter( "@Sort ", SqlDbType.Int,4),
new SqlParameter( "@Description ", SqlDbType.VarChar,500)
};
parameters[0].Value = model.InfoTypeName;
parameters[1].Value = model.Sort;
parameters[2].Value = model.Description;
你模仿这个写
[解决办法]
id是空的吧,
你判断一下
然后就是
你的逻辑
既然已经ExecuteNonQuery了还要select,
那你sqldataadapter是查询东西的吧
那你就ada.selectcommand.parameter.add( "@id ",sqldbtype.int).value=your id value
希望提供的信息对你有帮助
http://www.goodbus.cn
kaixin110@msn.com