【发布时间】:2014-08-06 06:24:03
【问题描述】:
我有 gridview 并且我在后端使用了存储过程。问题是我没有使用任何文本框或仅标签的gridview。
当我运行我的代码时,它显示一个编译错误,即 spproduct1 需要参数 @id,而该参数预计不会提供。 能否请您修复错误
public partial class WebForm1 : System.Web.UI.Page
{
string _strsql = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
string cs = ("Data Source=172.16.6.173;Initial Catalog=servion_hari;User ID=sa;Password=Servion@123");
_strsql = "select * from tblproduct where id=@id and Name=@Name and Description=@Description";
SqlConnection con = new SqlConnection(cs);
con.Open();
SqlDataAdapter da = new SqlDataAdapter("spgetproducts1", con);
SqlCommand cmd = new SqlCommand();
SqlParameter id = new SqlParameter("@id", SqlDbType.Int.ToString());
id.Value = GridView1.ToString();
da.SelectCommand.CommandType = CommandType.StoredProcedure;
con.Close();
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
}
【问题讨论】:
-
参数总是添加到SqlCommand。搜索SqlCommand。