我收到错误“无法隐式转换类型'int?' 到“int”。在返回行的 OrdersPerHour 上存在显式转换(您是否缺少演员表?)。我不知道为什么,因为我的 C# 技能不是那么先进。任何帮助,将不胜感激。
static int OrdersPerHour(string User)
{
int? OrdersPerHour;
OleDbConnection conn = new OleDbConnection(strAccessConn);
DateTime curTime = DateTime.Now;
try
{
string query = "SELECT COUNT(ControlNumber) FROM Log WHERE DateChanged > #" + curTime.AddHours(-1) + "# AND User = '" + User + "' AND Log.EndStatus in ('Needs Review', 'Check Search', 'Vision Delivery', 'CA Review', '1TSI To Be Delivered');";
OleDbCommand dbcommand = new OleDbCommand(query, conn);
dbcommand.Connection.Open();
dbcommand.CommandType = CommandType.Text;
OrdersPerHour = (int?)dbcommand.ExecuteScalar();
Console.WriteLine("Orders per hour for " + User + " is " + OrdersPerHour);
}
catch (OleDbException ex)
{
}
finally
{
conn.Close();
}
return OrdersPerHour;
}