ExecuteReader问题!无法执行请高手进来看看!顶者有分!!
ExecuteReader执行问题!
执行时候报错!错误如下:
ExecuteReader 需要打开的并且可用的连接。该连接的当前状态是 Closed。
行 130: SqlDataReader di = cmi.ExecuteReader();
我已经打开数据库了为什么还出现这样的情况呢?
我的源代码如下:
public class ParaStructure
{
public int P_AutoID;
public string P_GroupCountry;
public string P_GroupName;
public string P_AutoBrand;
public string P_AutoSeries;
public string P_AutoType;
public string P_AutoRealType;
public string P_AutoClass;
public string P_AutoMakeClass;
public string P_AutoYear;
public string P_AutoCheShu;
}
public static void Para(int Autoid)
{
SqlConnection con=DataCon.AutoCon();
SqlCommand cmd=new SqlCommand( "AutoInfoGetList ",con);
cmd.CommandType=CommandType.StoredProcedure;
SqlParameter DID=new SqlParameter( "@Aid ",SqlDbType.Int,4);
DID.Value=Autoid;
cmd.Parameters.Add(DID);
con.Open();
SqlDataReader dr=cmd.ExecuteReader();
ParaStructure PV=new ParaStructure();
if(dr.Read())
{
PV.P_AutoBrand=dr[ "AutoBrand "].ToString();
PV.P_AutoClass=dr[ "AutoClass "].ToString();
PV.P_AutoID=Convert.ToInt32(dr[ "AutoID "]);
PV.P_AutoMakeClass=dr[ "AutoMakeClass "].ToString();
PV.P_AutoRealType=dr[ "AutoRealType "].ToString();
PV.P_AutoSeries=dr[ "AutoSeries "].ToString();
PV.P_AutoType=dr[ "AutoType "].ToString();
PV.P_GroupCountry=dr[ "GroupCountry "].ToString();
PV.P_GroupName=dr[ "GroupName "].ToString();
}
dr.Close();
con.Close();
}
SqlConnection coe = DataCon.AutoCon();
coe.Open();
SqlCommand cmi = new SqlCommand( "cheParameter_cheGetList ",con);
cmi.CommandType = CommandType.StoredProcedure;
SqlParameter DIDD = new SqlParameter( "@Aid ",SqlDbType.Int,4);
DIDD.Value = Autoid;
cmi.Parameters.Add(DIDD);
SqlDataReader di = cmi.ExecuteReader();
ParaStructure PVV = new ParaStructure();
if(di.Read())
{
PVV.P_AutoID = Convert.ToInt32(dr[ "AutoID "]);
PVV.P_AutoYear = di[ "AutoYear "].ToString();
PVV.P_AutoCheShu = di[ "AutoCheShu "].ToString();
}
di.Close();
coe.Close();
到底是那里错误了呢??
------解决方案--------------------SqlCommand cmi = new SqlCommand( "cheParameter_cheGetList ",con);
这 里,你传入的还是con,应该是coe