-1

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.

  1. string type = "Beacon Comm" this is the sheet name.
  2. TargetBuildOledbConnection = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + FTPYTracker + "';Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';"
  3. string AssyColumn = "F" or whichever colum to search
  4. DateTimeSelection = "03/01/2020 00:00:00" or data from a date picker in the same format.

    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;
        }
    }
    

1 Answers1

0

Try this

comm.Parameters.Add("@prod", OleDbType.VarChar).Value = lastDayOfMonth;

Deleted
  • 91
  • 1
  • 13
  • I tried the following; comm.CommandText = string.Format(ci, "SELECT Count(*) FROM [" + type + "$" + AssyColumn + ":" + AssyColumn + "] WHERE " + AssyColumn + "<{0}", prodParamName); comm.Parameters.Add("@prod", OleDbType.VarChar).Value = lastDayOfMonth; And it returned: 'No value given for one or more required parameters.' – Ollie Sharratt Jan 03 '20 at 22:19
  • Can you try with removing the IMEX=1 from the TargetBuildOledbConnection connection string. It should be like "Provider=Microsoft.ACE.OLEDB.12.0; "Data Source='" + FilePath + "';Extended Properties=\"Excel 12.0;HDR=YES;\""; – Deleted Jan 03 '20 at 22:48
  • Unfortuantely no change at all with IMEX=1 removed – Ollie Sharratt Jan 03 '20 at 22:53