即時通訊試圖填補下拉列表,這讓我只有一個值。我怎樣才能把從數據庫中給出的所有值?填充下拉列表
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
爲什麼ExecuteNonQuery?使用ExecuteReader或任何其他方式獲取結果集,然後使用LINQ將其放入DDL。 – LINQ2Vodka