public static DataTable ExecuteSelectCommand(DbCommand dbcommand)
{
DataTable table;
try
{
//打开数据连接
dbcommand.Connection.Open();
DbDataReader reader = dbcommand.ExecuteReader();
table = new DataTable();
table.Load(reader);
reader.Close();
}
catch (Exception ex)
{ }
finally
{
dbcommand.Connection.Close();
}
return table;
}以上代码为什么在返回值时提示:use unassigned local variable 'table'
table 不是已经定义过了吗
{
DataTable table;
try
{
//打开数据连接
dbcommand.Connection.Open();
DbDataReader reader = dbcommand.ExecuteReader();
table = new DataTable();
table.Load(reader);
reader.Close();
}
catch (Exception ex)
{ }
finally
{
dbcommand.Connection.Close();
}
return table;
}以上代码为什么在返回值时提示:use unassigned local variable 'table'
table 不是已经定义过了吗
改为这样,table有可能没被附值就return
类似的,如果你这么写,也会报这个错:
void foo(bool b)
{
int i;
if (b) i = 1; // error, 因为if可能不执行
}