我想知道什麼是錯在此查詢我要選擇所有的行1列選擇所有的行具體列的查詢SQL Server 2008中
string command = "select money from User_Data";
SqlCommand update_money = new SqlCommand(command, con_string.con);
SqlDataReader money_reader;
money_reader = update_money.ExecuteReader();
我想知道什麼是錯在此查詢我要選擇所有的行1列選擇所有的行具體列的查詢SQL Server 2008中
string command = "select money from User_Data";
SqlCommand update_money = new SqlCommand(command, con_string.con);
SqlDataReader money_reader;
money_reader = update_money.ExecuteReader();
你在正確的軌道上 - 現在一次你有數據讀取器,你需要遍歷行:
string command = "select money from User_Data";
SqlCommand update_money = new SqlCommand(command, con_string.con);
SqlDataReader money_reader = update_money.ExecuteReader();
List<decimal> _allValues = new List<decimal>();
while(money_reader.Read())
{
_allValues.Add(money_reader.GetDecimal(0));
}
這裏假設你的money
列將SQL Server上decimal(x,y)
類型或money
的。
簡單地說... ?????????????? – JonH 2010-08-17 19:16:00
對您的問題更具體。究竟是什麼錯誤? 「它不起作用」不是一個好問題。 – tenfour 2010-08-17 19:16:24
當我寫 時它給了我一個例外tempmoney1 =(float)Convert.ToDouble(money_reader.GetValue(0).ToString()); tempmoney2 =(float)Convert.ToDouble(money_reader.GetValue(1).ToString()); – kartal 2010-08-17 19:32:18