Home > Net >  ExecuteReader requirement is open and available Connection. The current state of the Connection is c
ExecuteReader requirement is open and available Connection. The current state of the Connection is c

Time:04-12

red part of the error: ExecuteReader requirement is open and available Connection, the current state of the Connection is closed, "=" near a syntax error,
///& lt; Summary>
///according to the student ID query details
///& lt;/summary>
///& lt; Param name="studentId" & gt; Students ID
///& lt; Returns> & lt;/returns>
Public Students GetStudentDetail (string studentId)
{

String SQL=the string. Format (" select StudentId, StudentName, Gender, Birthday, AttendanceNO, Stulmage, Age, Phone, StudentAddress, IdentityNO, StudentClass. Every, the ClassName from Students inner join StudentClass on StudentClass. Every Students. Every where StudentId={0} ", StudentId);


SqlConnection conn=new SqlConnection (connString);//link to the database
SqlCommand CMD=new SqlCommand (SQL, conn);//send commands to the database
Conn. The Open ();//open the database connection
SqlDataReader reader=CMD. ExecuteReader (CommandBehavior. CloseConnection);
Students Students=new Students ();
If (reader. The Read ())
{
Students=new students ()
{
StudentId=the Convert. ToInt32 (reader (" StudentId ")),
StudentName=reader [r]. "StudentName" ToString (),
IdentityNO=reader [r]. "IdentityNO" ToString (),
Gender=reader [r]. "Gender" ToString (),
Birthday=the Convert. ToDateTime (reader [" Birthday "]),
AttendanceNO=reader [r]. "AttendanceNO" ToString (),
Stulmage=reader [r]. "Stulmage" ToString (),
Age=the Convert. ToInt32 (reader (" Age ")),
Phone=reader (" Phone "). The ToString (),
StudentAddress=reader [r]. "StudentAddress" ToString (),
Every Convert. ToInt32 (reader [" every "]),
The ClassName=reader [r]. "ClassName" ToString ()

};
}
Return students;
}
  •  Tags:  
  • C#
  • Related