我想從數據讀取器接收兩個值。但我不知道如何將這個問題放入一個查詢中。我怎樣才能通過使用一個sqldatareader來接收它?組合查詢並使用1個數據讀取器
string query = "select date from ars.kmstand where ritnr=(select max(ritnr) from ars.kmstand)";
string query2 = "select nr from ars.kmstand where ritnr=(select max(ritnr) from ars.kmstand)";
SqlCommand com = new SqlCommand(query2, conn);
SqlDataReader rt = com.ExecuteReader();
while (rt.Read())
{
ritnr = rt.GetInt32(0);
}
rt.Close();
SqlCommand comm = new SqlCommand(query, conn);
SqlDataReader rd = comm.ExecuteReader();
while (rd.Read())
{
value = rd.GetSqlDateTime(0);
}
謝謝,更短,更好。真的有幫助! – tosorro