【发布时间】:2020-12-03 22:27:09
【问题描述】:
当我对整个表进行求和时,我想让我的非空 DateTime 列 null 不为空,这样我就不会得到日期时间 1/1/0001 12:00:00 的任何值。我想在这个方法中添加任何可能的语句。我尝试解析它,但它不起作用,但对于 Amount 来说完全没问题。
private void SumOfRecords_Button(object sender, RoutedEventArgs e)
{
ObservableCollection<Receipt> receipts = new ReceiptDAO().GetAllReceiptsFromPiName();
Receipt receipt = new Receipt();
if (receipt.DateTime != null)
{
Receipt receipt0 = new Receipt()
{
DateTime = DateTime.TryParse(),
Amount = new ReceiptDAO().SumOfRecords("Amount")
};
receipts.Add(receipt);
this.Dispatcher.Invoke(() => ReceiptList.ItemsSource = receipts);
}
}
这是我正在编写查询的SumOfRecords 的方法。
public double SumOfRecords(string columnName)
{
ObservableCollection<Receipt> receipts = new ReceiptDAO().GetAllReceiptsFromPiName();
Receipt receipt = new Receipt();
string commandstring;
commandstring = "select Sum(" + columnName + ") from " + getTable();
using (SQLiteConnection connection = ConnectToDatabase())
{
using (SQLiteCommand command = new SQLiteCommand(commandstring, connection))
{
using (SQLiteDataReader reader = command.ExecuteReader())
{
reader.Read();
return reader.GetDouble(0);
}
}
}
}
【问题讨论】:
-
SumOfRecords中有什么内容? -
拥有minimal reproducible example 会很棒。
-
我刚刚添加了 SumOfRecords 方法中的内容。