C# Programming
05-06-2009, 01:17 PM
Good Day All
I have the Following Code in my DAL
public SqlDataReader Get_Staff_Cycles_internal(String DB)
{
SqlDataReader rd = null;
strcon = GetConnectionString(DB);
con = new SqlConnection(strcon);
cmdselect = new SqlCommand();
cmdselect.CommandType = CommandType.StoredProcedure;
cmdselect.CommandText = "[dbo].[sp_Get_Staff_Cycles_internal]";
cmdselect.CommandTimeout = 0;
cmdselect.Connection = con;
try
{
con.Open();
rd = cmdselect.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (SqlException)
{
throw;
}
finally
{
if (con != null)
{
con.Close();
}
}
return rd;
}
and Am using this code Like this In BLL
public SqlDataReader Get_Staff_Cycles(int ACTIVITY_ID, String DB)
{
DAL.DAL obj = new DAL.DAL();
SqlDataReader rd = null;
try
{
obj.Get_Staff_Cycles(ACTIVITY_ID, DB);
rd = obj.Get_Staff_Cycles_internal(DB);
}
catch (SqlException)
{
throw;
}
finally
{
obj = null;
}
return rd;
}
And am Calling it like this in PL(Presentation Layer)
private void Bind_Grid_For_Staff()
{
SqlDataReader rd = null;
BLL.BLL obj = new BLL.BLL();
try
{
if (Convert.ToString(Session["Selected_ID_Bind"]).Length > 6)
{
//If the Activities are multiselect
String Activityid = Convert.ToString(Session["Selected_ID_Bind"]);
if (Activityid != null || Activityid != "")
{
ArrayList Final_String = (ArrayList)Fixed_String_Multi(Activityid);
for (int i = 0; i < Final_String.Count; i++)
{
rd = obj.Get_Staff_Cycles(Convert.ToInt32(Final_String[i]), Convert.ToString(Session["ActiveDatabase"]));
}
if (rd != null)
{
while (rd.Read())
{
Gridstaff.DataSourceID = null;
Gridstaff.DataSource = rd;
Gridstaff.DataBind();
}
}
}
else
{
lblGridStaff.Text = "Could not Bind StaffGrid";
lblGridStaff.ForeColor = System.Drawing.Color.Red;
}
}
else
{
if (Convert.ToString(Session["Selected_ID_Bind"]) != null)
{
String Activityid = Convert.ToString(Session["Selected_ID_Bind"]);
if (Activityid != null || Activityid != "")
{
ArrayList Final_String = (Fixed_String(Activityid));
for (int d = 0; d < Final_String.Count; d++)
{
rd = obj.Get_Staff_Cycles(Convert.ToInt32(Final_String[d]), Convert.ToString(Session["ActiveDatabase"]));
}
if (rd != null)
{
Gridstaff.DataSource = rd;
Gridstaff.DataBind();
rd.Close();
}
}
else
{
lblGridStaff.Text = "Could not Bind StaffGrid";
lblGridStaff.ForeColor = System.Drawing.Color.Red;
}
}
else
{
Response.Redirect("SubjectStaff.aspx", false);
}
}
}
catch (ApplicationException e)
{
lblStatus.Text = e.Message.ToString();
}
}
i get an Error
Invalid attempt to call MetaData when reader is closed.
and its Poiting to the part that Binds the gridview here
Gridstaff.DataBind();
Thank you
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
I have the Following Code in my DAL
public SqlDataReader Get_Staff_Cycles_internal(String DB)
{
SqlDataReader rd = null;
strcon = GetConnectionString(DB);
con = new SqlConnection(strcon);
cmdselect = new SqlCommand();
cmdselect.CommandType = CommandType.StoredProcedure;
cmdselect.CommandText = "[dbo].[sp_Get_Staff_Cycles_internal]";
cmdselect.CommandTimeout = 0;
cmdselect.Connection = con;
try
{
con.Open();
rd = cmdselect.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (SqlException)
{
throw;
}
finally
{
if (con != null)
{
con.Close();
}
}
return rd;
}
and Am using this code Like this In BLL
public SqlDataReader Get_Staff_Cycles(int ACTIVITY_ID, String DB)
{
DAL.DAL obj = new DAL.DAL();
SqlDataReader rd = null;
try
{
obj.Get_Staff_Cycles(ACTIVITY_ID, DB);
rd = obj.Get_Staff_Cycles_internal(DB);
}
catch (SqlException)
{
throw;
}
finally
{
obj = null;
}
return rd;
}
And am Calling it like this in PL(Presentation Layer)
private void Bind_Grid_For_Staff()
{
SqlDataReader rd = null;
BLL.BLL obj = new BLL.BLL();
try
{
if (Convert.ToString(Session["Selected_ID_Bind"]).Length > 6)
{
//If the Activities are multiselect
String Activityid = Convert.ToString(Session["Selected_ID_Bind"]);
if (Activityid != null || Activityid != "")
{
ArrayList Final_String = (ArrayList)Fixed_String_Multi(Activityid);
for (int i = 0; i < Final_String.Count; i++)
{
rd = obj.Get_Staff_Cycles(Convert.ToInt32(Final_String[i]), Convert.ToString(Session["ActiveDatabase"]));
}
if (rd != null)
{
while (rd.Read())
{
Gridstaff.DataSourceID = null;
Gridstaff.DataSource = rd;
Gridstaff.DataBind();
}
}
}
else
{
lblGridStaff.Text = "Could not Bind StaffGrid";
lblGridStaff.ForeColor = System.Drawing.Color.Red;
}
}
else
{
if (Convert.ToString(Session["Selected_ID_Bind"]) != null)
{
String Activityid = Convert.ToString(Session["Selected_ID_Bind"]);
if (Activityid != null || Activityid != "")
{
ArrayList Final_String = (Fixed_String(Activityid));
for (int d = 0; d < Final_String.Count; d++)
{
rd = obj.Get_Staff_Cycles(Convert.ToInt32(Final_String[d]), Convert.ToString(Session["ActiveDatabase"]));
}
if (rd != null)
{
Gridstaff.DataSource = rd;
Gridstaff.DataBind();
rd.Close();
}
}
else
{
lblGridStaff.Text = "Could not Bind StaffGrid";
lblGridStaff.ForeColor = System.Drawing.Color.Red;
}
}
else
{
Response.Redirect("SubjectStaff.aspx", false);
}
}
}
catch (ApplicationException e)
{
lblStatus.Text = e.Message.ToString();
}
}
i get an Error
Invalid attempt to call MetaData when reader is closed.
and its Poiting to the part that Binds the gridview here
Gridstaff.DataBind();
Thank you
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/