ORMを使用したくないがsqlComandを使用したい場合は、次のことができます。
protected void Button1_Click(object sender, EventArgs e)
{
Fill(60);
}
protected void Button2_Click(object sender, EventArgs e)
{
Fill(30);
}
private void Fill(int numberOfDays)
{
using (SqlConnection connection = new SqlConnection("connectionString"))
{
connection.Open();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand("stored procedure name", connection);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
sda.SelectCommand.Parameters.AddWithValue("@NumOfDays", numberOfDays);
DataSet ds = new DataSet();
sda.Fill(ds, "result_table");
GridView1.DataSource = ds.Tables["result_table"];
GridView1.DataBind();
}
}
vb:
Protected Sub Button1_Click(sender As Object, e As EventArgs)
Fill(60)
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs)
Fill(30)
End Sub
Private Sub Fill(numberOfDays As Integer)
Using connection As New SqlConnection("connectionString")
connection.Open()
Dim sda As New SqlDataAdapter()
sda.SelectCommand = New SqlCommand("stored procedure name", connection)
sda.SelectCommand.CommandType = CommandType.StoredProcedure
sda.SelectCommand.Parameters.AddWithValue("@NumOfDays", numberOfDays)
Dim ds As New DataSet()
sda.Fill(ds, "result_table")
GridView1.DataSource = ds.Tables("result_table")
GridView1.DataBind()
End Using
End Sub