Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > .net generic problem

Reply
Thread Tools

.net generic problem

 
 
Jeff
Guest
Posts: n/a
 
      11-02-2006
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.ConnectionStrin gs["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;
}


 
Reply With Quote
 
 
 
 
Mark Fitzpatrick
Guest
Posts: n/a
 
      11-02-2006
I haven't played with generics yet myself, but the logitems variable has to
be instantiated as some sort of list in order to use it. Although you've
declared it, it's still not instantiated so it's throwing an error because,
as you've coded, it's still set to null.

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Jeff" <(E-Mail Removed)> wrote in message
news:%23pszlVh$(E-Mail Removed)...
> 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.ConnectionStrin gs["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;
> }
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
not just generic type programming,but also parallism generic syntaxprogramming?? minlearn C++ 2 03-13-2009 05:17 PM
generic interfaces with generic methods Murat Tasan Java 1 02-03-2009 12:17 PM
Generic class in a non generic class nramnath@gmail.com Java 2 07-04-2006 07:24 AM
Starting Error Msg: "Generic Host Process For WIN 32 Service has encountered a problem..." : Meaning Of, Please ? Robert11 Computer Support 0 03-02-2005 07:43 PM
Generic Host Process for Win32 has encountered a problem and needs to close??????? KarateKid Computer Support 5 08-11-2003 09:14 PM



Advertisments