J
Jeff
Hey
asp.net 2.0
The code below throws an "Object reference not set to an instance of an
object" exception at the "logitems.Add(item);" line...
the "LogItem item" object is successfully created, but it the exception is
thrown when trying to put this object on the list... maybe it's because the
"LogItem item" isn't declared as a <List>.. I'm not sure.. well, I'm more
like a newbie when it comes to Generic .net.....
Any suggestions on how to solve this is welcome!
public static List<LogItem> GetLog()
{
List<LogItem> logitems = null;
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["aspnet_DB"].ConnectionString);
SqlCommand cmd = new SqlCommand("AH_Get", conn);
SqlDataReader reader;
cmd.CommandType = CommandType.StoredProcedure;
try
{
conn.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
LogItem item = new LogItem(reader.GetString(0),
reader.GetString(1), reader.GetDateTime(2));
logitems.Add(item);
}
}
catch (SqlException ex)
{
}
finally
{
conn.Close();
}
return logitems;
}
asp.net 2.0
The code below throws an "Object reference not set to an instance of an
object" exception at the "logitems.Add(item);" line...
the "LogItem item" object is successfully created, but it the exception is
thrown when trying to put this object on the list... maybe it's because the
"LogItem item" isn't declared as a <List>.. I'm not sure.. well, I'm more
like a newbie when it comes to Generic .net.....
Any suggestions on how to solve this is welcome!
public static List<LogItem> GetLog()
{
List<LogItem> logitems = null;
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["aspnet_DB"].ConnectionString);
SqlCommand cmd = new SqlCommand("AH_Get", conn);
SqlDataReader reader;
cmd.CommandType = CommandType.StoredProcedure;
try
{
conn.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
LogItem item = new LogItem(reader.GetString(0),
reader.GetString(1), reader.GetDateTime(2));
logitems.Add(item);
}
}
catch (SqlException ex)
{
}
finally
{
conn.Close();
}
return logitems;
}