0
我已經設法從MS Access數據庫中獲得一筆款項,但我試圖添加的數字都是正數和負數。在上一個問題中獲取MS訪問數據庫的總和
如何將正數和負數加在一起。
下面的代碼返回的總和,但沒有考慮到負數,它把它們視爲正面,這可以糾正?
com = new OleDbCommand("SELECT sum([Points]) FROM FlightPoints WHERE [Person] =?",
Program.DB_CONNECTION);
com.Parameters.Add(new OleDbParameter("", c.ID));
dr = com.ExecuteReader();
if (dr.Read())
{
try
{
string[] subitems = new string[2]; // set number of items in the list
subitems[0] = c.Rank.String + " " + c.FirstName + " " + c.Surname;
subitems[1] = Convert.ToInt32(dr.GetDouble(0)).ToString();
ListViewItem listItem = new ListViewItem(subitems);
CadetPointlistView.Items.Add(listItem); // add all the subitems to the table
}
catch
{
}
}
「下面的代碼返回的總和,但沒有考慮到負數,它把它們視爲積極的」 - 這似乎並不正確。請發佈表格中的一些示例數據以及您的查詢爲您提供的結果。 – Dai 2015-03-02 18:20:24
@戴。我在我的方式中發現錯誤,它不是上面的代碼,它是我的插入語句,沒有插入負數。 – Ryanagray 2015-03-02 18:33:16