User-271186128 posted
Hi BerrySmith,
how can i pass this selection to below procedure where it has logic to filter.
Suppose the stored procedure as below:
CREATE PROCEDURE dbo.usp_GetReportsWithinRange
@Start_Date smalldatetime,
@End_Date smalldatetime
AS
BEGIN
SET NOCOUNT ON;
SELECT * --You can define columns that you want to pull
FROM dbo.Sales_Report
WHERE Sales_Date >= @Start_Date AND
Sales_Date <= @End_Date
END
GO
First, you could get the DropDownList Property (SelectedItem.Text, SelectedItem.Value, SelectedValue).
Then, refer to the following code to call the stored procedure:
//get connection string
string constr = ConfigurationManager.ConnectionStrings["MyTestDBConnStr2"].ToString();
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(constr))
{
// the procedure name
using (SqlCommand cmd = new SqlCommand("usp_GetReportsWithinRange", con))
{
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
//add parameters
cmd.Parameters.AddWithValue("@Start_Date", startdate);
cmd.Parameters.AddWithValue("@End_Date", enddate);
SqlDataAdapter ada = new SqlDataAdapter();
ada.SelectCommand = cmd;
ada.Fill(dt);
}
}
GridView1.DataSource = dt;
GridView1.DataBind();
Best regards,
Dillion