My overall goal is to be able to type in information into my textbox and click a button to search and get results from the database using gridview. So far I have my SqlDataSource
SQL statement set up. I need to figure out how to link my button on click event with my SqlDataSource
and Textbox
.
Here is what I have so far:
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection("Data Source=********;Initial Catalog=*******;User ID=*******;Password=*******");
connection.Open();
}
I am not sure how to use my SqlDataSource
that I have already set up.
Updated Code:
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);
}