public static int maxsql(string sql) //取得最大记录的函数,sql传入要as max1
{
int returnValue;
System.Data.OleDb.OleDbCommand comm1 = new System.Data.OleDb.OleDbCommand();
System.Data.OleDb.OleDbConnection conn1 = new System.Data.OleDb.OleDbConnection();
System.Data.OleDb.OleDbDataReader dr_temp;
conn1.ConnectionString = connstr;
conn1.Open();
comm1.Connection = conn1;
comm1.CommandText = sql;
dr_temp = comm1.ExecuteReader(CommandBehavior.CloseConnection);
if (dr_temp.Read())
{
if (dr_temp["max1"] == System.DBNull.Value)
{
returnValue = 0;
}
else
{
returnValue =Convert.ToInt32(dr_temp["max1"]);
}
}
dr_temp.Close();
conn1.Close();
return returnValue;
}在最后一行return returnValue;中提示
“未赋值的局部变量 returnValue;”
为什么呢?我对C#不是很明白