C# Programming
04-22-2009, 01:24 PM
Good Afternoon All
As you know in South Africa today is a Election day, i think my ado.net code went to the Elections tooo
i have this code in my DAL
public DataSet Lis_Databases(String DB)
{
Strcon = GetConnectionString(DB);
con = new SqlConnection(Strcon);
cmdselect = new SqlCommand();
cmdselect.CommandText = "[dbo].[sp_ListDatabasesOfType_Booking]";
cmdselect.CommandType = CommandType.StoredProcedure;
cmdselect.Connection = con;
da = new SqlDataAdapter();
da.SelectCommand = cmdselect;
DataSet ds = new DataSet();
try
{
con.Open();
da.Fill(ds);
}
catch (SqlException)
{
throw;
}
finally
{
if (con != null)
{
con.Close();
}
}
return ds;
}
and i call this code in my BLL like this
public DataSet Lis_Databases(String DB)
{
DAL.DAL obj = new DAL.DAL();
DataSet ds = new DataSet();
try
{
ds = obj.Lis_Databases(DB);
}
catch (SqlException)
{
throw;
}
finally
{
obj = null;
}
return ds;
}
And call use it like this in my PL(Presention Layer)
private void List_Databases_Grid()
{
BLL.BLL obj = new BLL.BLL();
DataSet ds = new DataSet();
try
{
ds = obj.Lis_Databases(Convert.ToString(Session["ActiveDatabase"]));
if (ds.Tables[0].Rows.Count > 0)
{
GridView_Database_list.DataSource = ds;
GridView_Database_list.DataBind();
}
else
{
lblMessage.Text = "No Booking Database Avaiable,Create one";
lblMessage.Visible = true;
lblMessage.ForeColor = System.Drawing.Color.Red;
}
}
catch (SqlException ex)
{
lblMessage.Visible = true;
lblMessage.Text = "The List cannot be Binded, Please Contact ITS" + ex.Message;
lblMessage.ForeColor = System.Drawing.Color.Red;
}
finally
{
obj = null;
}
}
when my code Comes to this line
if (ds.Tables[0].Rows.Count > 0)
{
The evualuation, it passes and that mean records had been returned, now when it gets to this line
GridView_Database_list.DataSource = ds;
it says
Object reference not set to an instance of an object.
i have Initialized the Dataset everywhere as you can see above
what have i done wrong?
You can still Comment on my Error handling
Thank you
Vuyiswa Maseko
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/
As you know in South Africa today is a Election day, i think my ado.net code went to the Elections tooo
i have this code in my DAL
public DataSet Lis_Databases(String DB)
{
Strcon = GetConnectionString(DB);
con = new SqlConnection(Strcon);
cmdselect = new SqlCommand();
cmdselect.CommandText = "[dbo].[sp_ListDatabasesOfType_Booking]";
cmdselect.CommandType = CommandType.StoredProcedure;
cmdselect.Connection = con;
da = new SqlDataAdapter();
da.SelectCommand = cmdselect;
DataSet ds = new DataSet();
try
{
con.Open();
da.Fill(ds);
}
catch (SqlException)
{
throw;
}
finally
{
if (con != null)
{
con.Close();
}
}
return ds;
}
and i call this code in my BLL like this
public DataSet Lis_Databases(String DB)
{
DAL.DAL obj = new DAL.DAL();
DataSet ds = new DataSet();
try
{
ds = obj.Lis_Databases(DB);
}
catch (SqlException)
{
throw;
}
finally
{
obj = null;
}
return ds;
}
And call use it like this in my PL(Presention Layer)
private void List_Databases_Grid()
{
BLL.BLL obj = new BLL.BLL();
DataSet ds = new DataSet();
try
{
ds = obj.Lis_Databases(Convert.ToString(Session["ActiveDatabase"]));
if (ds.Tables[0].Rows.Count > 0)
{
GridView_Database_list.DataSource = ds;
GridView_Database_list.DataBind();
}
else
{
lblMessage.Text = "No Booking Database Avaiable,Create one";
lblMessage.Visible = true;
lblMessage.ForeColor = System.Drawing.Color.Red;
}
}
catch (SqlException ex)
{
lblMessage.Visible = true;
lblMessage.Text = "The List cannot be Binded, Please Contact ITS" + ex.Message;
lblMessage.ForeColor = System.Drawing.Color.Red;
}
finally
{
obj = null;
}
}
when my code Comes to this line
if (ds.Tables[0].Rows.Count > 0)
{
The evualuation, it passes and that mean records had been returned, now when it gets to this line
GridView_Database_list.DataSource = ds;
it says
Object reference not set to an instance of an object.
i have Initialized the Dataset everywhere as you can see above
what have i done wrong?
You can still Comment on my Error handling
Thank you
Vuyiswa Maseko
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/