【发布时间】:2014-06-17 13:09:54
【问题描述】:
我的总体目标是能够在我的文本框中输入信息并单击按钮以使用 gridview 从数据库中搜索和获取结果。到目前为止,我已经设置了我的SqlDataSource SQL 语句。我需要弄清楚如何将我的点击事件按钮与我的SqlDataSource 和Textbox 链接起来。
这是我目前所拥有的:
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection("Data Source=********;Initial Catalog=*******;User ID=*******;Password=*******");
connection.Open();
}
我不知道如何使用我已经设置的SqlDataSource。
更新代码:
SqlConnection sqlCon = new SqlConnection("*******");
SqlDataAdapter dt = new SqlDataAdapter();
DataSet ds = new DataSet();
try
{
sqlCon.Open();
dt.SelectCommand = new SqlCommand("SELECT* FROM Core.Form_Section_SubSection_Item_Rel WHERE ([DataCollectionPeriodID] = @DataCollectionPeriodID)", sqlCon);
dt.Fill(ds);
sqlCon.Close();
GridView1.DataBind();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
【问题讨论】:
-
您是否使用存储过程获取数据?
-
@paabobo 否 只是一个简单的 SQL select from where 语句
标签: sql sql-server button gridview sqldatasource