473,386 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

.net generic problem

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<LogItemGetLog()
{
List<LogItemlogitems = 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;
}
Nov 2 '06 #1
1 937
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" <it************@hotmail.com.NOSPAMwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
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<LogItemGetLog()
{
List<LogItemlogitems = 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;
}

Nov 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael Kennedy [UB] | last post by:
Hi Everyone, I have this multithreaded C# windows forms application which does a lot of image processing. Occasionally, I get the following error: A generic error occurred in GDI+....
17
by: Andreas Huber | last post by:
What follows is a discussion of my experience with .NET generics & the ..NET framework (as implemented in the Visual Studio 2005 Beta 1), which leads to questions as to why certain things are the...
3
by: Tigger | last post by:
I have an object which could be compared to a DataTable/List which I am trying to genericify. I've spent about a day so far in refactoring and in the process gone through some hoops and hit some...
4
by: Charles Churchill | last post by:
I apologize if this question has been asked before, but after about half an hour of searching I haven't been able to find an answer online. My code is beloiw, with comments pertaining to my...
9
by: mps | last post by:
I want to define a class that has a generic parameter that is itself a generic class. For example, if I have a generic IQueue<Tinterface, and class A wants to make use of a generic class that...
13
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an...
0
by: epoxyparser | last post by:
Hi all, I work as a glue coder and often have to interface existing mechanisms with other platforms. Creating bridge code between command-line functionality and desktop GUIs takes up a lot of that...
10
by: Egghead | last post by:
Hi all, Can someone kindly enough point me to some situations that we shall or "must" use Generic Class? I can foresee the Generic Method is powerful, but I can not find a single situation that...
3
by: Łukasz | last post by:
I have project that uses managed c++ where I use c - library, this library contains some variables named generic, during compilation I get error: Error 1 error C2146: syntax error : missing ';'...
26
by: raylopez99 | last post by:
Here is a good example that shows generic delegate types. Read this through and you'll have an excellent understanding of how to use these types. You might say that the combination of the generic...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.