我试图填写一个下拉列表,它只给了我一个值。我怎样才能把从数据库中给出的所有值?
var con = new SqlConnection("server=(local);Initial Catalog=Test;Integrated Security=True");
try
{
con.Open();
SqlCommand command = new SqlCommand("GetDates", con);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@Dates", SqlDbType.DateTime, 50, ParameterDirection.Output, false, 0, 50, "Dates", DataRowVersion.Default, null));
command.Parameters.Add(new SqlParameter("@Hours", SqlDbType.NChar, 10, ParameterDirection.Output, false, 0, 50, "Hours", DataRowVersion.Default, null));
command.UpdatedRowSource = UpdateRowSource.OutputParameters;
command.ExecuteNonQuery();
DateTime Dates = (DateTime)command.Parameters["@Dates"].Value;
string Hours = (string)command.Parameters["@Hours"].Value;
day.Items.Add(Hours);
}
catch (Exception ex)
{
con.Close();
}
这是SP
ALTER PROCEDURE GetDates (@Dates datetime OUTPUT, @Hours NCHAR(10) OUTPUT)
AS
SELECT @Dates = Dates, @Hours = Hours from test..Dates where taken = 0
GO