我希望你能伸出援助之手。
当该列的数据来自datagridview
时,如何在storedProcedure
中获取计算列。它只是与sp
一起返回的一个值。我不确定这是否可行,或者我应该在sql
字符串中包含一个函数sql
来执行该任务?
答案 0 :(得分:0)
如何以编程方式进行.. 你点击例如加载的按钮.. 这是加载存储过程的典型代码示例。 你可以将代码移动到page_load而不是Button1_click .. 我只是发布了重要的代码片段。
public partial class WebForm4 : System.Web.UI.Page {
SqlConnection sqlcon = new SqlConnection("Data Source=Local-host;Initial
Catalog=HRM_Login;Integrated Security=True");
SqlCommand sqlcmd = new SqlCommand();
SqlDataAdapter sqladp = new SqlDataAdapter();
DataSet ds = new DataSet();
protected void Button1_Click(object sender, EventArgs e)
{
Label2.Visible = true;
GridView1.Visible = true;
sqlcmd.Connection = sqlcon;
sqlcmd.CommandText = "GetStudentName";
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.Add(new SqlParameter("@Studentid", SqlDbType.Int)).Value
= Int32.Parse(txt_studentid.Text);
sqladp.SelectCommand = sqlcmd;
sqladp.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
}
well u can try
GridView1.DataSource = ds; instead of GridView1.DataSource = ds.Tables[0];