这是我正在使用的代码。我想将下拉选择的项目作为输入传递给存储过程并执行它。我该如何实现?
public class DaysForEvents
{
public DataSet GetDaysForEvents(//This should be my input to stored procedure (i.e) dropdownselected value)
{
SqlConnection con = new SqlConnection(CommonSettings.GetEventsConnectionString());
try
{
SqlCommand sqlcmd = new SqlCommand("proc_fetch_event_days", con);
SqlDataAdapter sqlda = new SqlDataAdapter(sqlcmd);
DataSet ds = new DataSet();
//DateFilter = 0;
//StatusFilter = 0;
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.AddWithValue("@event_id", Event_id);
// sqlcmd.Parameters["@UserID"].Value = UserID;
con.Open();
sqlda.Fill(ds);
con.Close();
return ds;
}
据我了解,您想要这个。
//get dropdown selected value and store in a variable
var eventId = dropdown.SelectedValue;
//pass this variable in the GetDaysForEvents method to get DataSet.
var dataSet = GetDaysForEvents(eventId);
我是一名优秀的程序员,十分优秀!