我正在尝试计算某个日期之前一列的值的数量。以下是我目前的尝试。没有where部分,我可以运行此问题,但是,当然需要返回正确的值。
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + FTPYTracker + "';Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';"
DateTimeSelection =“ 03/01/2020 00:00:00”或来自日期选择器的数据采用相同格式。
public double GetInProgressOledb(string type, OleDbConnection FTPYBuildOleDbConnection, string AssyColumn, DateTime Selection)
{
const string prodParamName = "@prod";
double lastDayOfMonth = (new DateTime(Selection.Year, Selection.Month, 1).AddMonths(1).AddDays(-1)).ToOADate();
using (OleDbCommand comm = new OleDbCommand())
{
comm.Connection = FTPYBuildOleDbConnection;
comm.CommandText = string.Format(ci, "SELECT Count(*) FROM [" + type + "$" + AssyColumn + ":" + AssyColumn + "] WHERE [" + AssyColumn + "$] = #" + lastDayOfMonth + "#");
//comm.Parameters.Add(prodParamName, OleDbType.VarChar);
//comm.Parameters[prodParamName].Value = lastDayOfMonth;
double rowCount = Convert.ToDouble((int)comm.ExecuteScalar());
return rowCount;
}
}
尝试一下
comm.Parameters.AddWithValue("@prodParamName", OleDbType.VarChar).Value = lastDayOfMonth;