PureDevelopers
IS-IT--Management
I have a page with two controls that are databound:
I am using a single connection with two commands, and the code is breaking when I attempt to execute the second reader.
The error says "There is already an open DataReader associated with this Command which must be closed first.", but it is a totally seperate command. I am confused. Is this not how you do this??
string strConnection = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection Conn = new SqlConnection(strConnection);
Conn.Open();
string SQLLevel = "SELECT [ID] = NULL, [Name] = '--' UNION SELECT [ID], [Name] FROM [Level]";
SqlCommand cmdLevel = new SqlCommand(SQLLevel, Conn);
this.ddlLevel.DataSource = cmdLevel.ExecuteReader();
this.ddlLevel.DataTextField = "Name";
this.ddlLevel.DataValueField = "ID";
this.ddlLevel.DataBind();
cmdLevel.Dispose();
string SQLSide = "SELECT [ID] = NULL, [Name] = '--' UNION SELECT [ID], [Name] FROM [Side]";
SqlCommand cmdSide = new SqlCommand(SQLSide, Conn);
this.ddlSide.DataSource = cmdSide.ExecuteReader();
this.ddlSide.DataTextField = "Name";
this.ddlSide.DataValueField = "ID";
this.ddlSide.DataBind();
cmdSide.Dispose();
I am using a single connection with two commands, and the code is breaking when I attempt to execute the second reader.
The error says "There is already an open DataReader associated with this Command which must be closed first.", but it is a totally seperate command. I am confused. Is this not how you do this??
string strConnection = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection Conn = new SqlConnection(strConnection);
Conn.Open();
string SQLLevel = "SELECT [ID] = NULL, [Name] = '--' UNION SELECT [ID], [Name] FROM [Level]";
SqlCommand cmdLevel = new SqlCommand(SQLLevel, Conn);
this.ddlLevel.DataSource = cmdLevel.ExecuteReader();
this.ddlLevel.DataTextField = "Name";
this.ddlLevel.DataValueField = "ID";
this.ddlLevel.DataBind();
cmdLevel.Dispose();
string SQLSide = "SELECT [ID] = NULL, [Name] = '--' UNION SELECT [ID], [Name] FROM [Side]";
SqlCommand cmdSide = new SqlCommand(SQLSide, Conn);
this.ddlSide.DataSource = cmdSide.ExecuteReader();
this.ddlSide.DataTextField = "Name";
this.ddlSide.DataValueField = "ID";
this.ddlSide.DataBind();
cmdSide.Dispose();