[英]How do you add parameters to a count query ran on an excel spreadsheet via oledb?
I am trying to count the number of values on a column that are before a certain date.我正在尝试计算某个日期之前的列上的值数。 The below is my current attempt.以下是我目前的尝试。 I am able to run this no problem without the where section, however of course this is needed for the correct value to be returned.如果没有 where 部分,我可以毫无问题地运行它,但是当然这需要返回正确的值。
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + FTPYTracker + "';Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';"
TargetBuildOledbConnection = @"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" or data from a date picker in the same format. 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.Add("@prod", OleDbType.VarChar).Value = lastDayOfMonth;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.