Cannot implicitly convert type 'int?' to 'int'.

前端 未结 10 1599
野性不改
野性不改 2021-01-03 19:34

I\'m getting the error \"Cannot implicitly convert type \'int?\' to \'int\'. An explicit conversion exists (are you missing a cast?)\" on my OrdersPerHour at the return line

10条回答
  •  再見小時候
    2021-01-03 20:38

    Well you're casting OrdersPerHour to an int?

    OrdersPerHour = (int?)dbcommand.ExecuteScalar();
    

    Yet your method signature is int:

    static int OrdersPerHour(string User)
    

    The two have to match.


    Also a quick suggestion -> Use parameters in your query, something like:

    string query = "SELECT COUNT(ControlNumber) FROM Log WHERE DateChanged > ? AND User = ? AND Log.EndStatus in ('Needs Review', 'Check Search', 'Vision Delivery', 'CA Review', '1TSI To Be Delivered')";
    OleDbCommand dbcommand = new OleDbCommand(query, conn);
    dbcommand.Parameters.Add(curTime.AddHours(-1));
    dbcommand.Parameters.Add(User);
    

提交回复
热议问题