har*_*ari -3 c# asp.net gridview
我有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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
对于存储过程方式:
SqlConnection con = new SqlConnection(cs);
SqlDataAdapter da = new SqlDataAdapter("spgetproducts1", con);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
//first paramenter: parameter name, second parameter: parameter value of object type
//using this way you can add more parameters
da.SelectCommand.Parameters.AddWithValue("@id", GridView1.ToString());
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
Run Code Online (Sandbox Code Playgroud)
题; 你想用GridView1.ToString()实现什么?
| 归档时间: |
|
| 查看次数: |
23444 次 |
| 最近记录: |