TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jason
NA
1
0
How can I check for a null value while loading a list with a reader??
Jan 22 2007 6:15 PM
The description field is null in my database and whenever the following code tries to load a list it throws an exception, I have searched all over and tried several things I thought would work. I am new to C# coming from VB so forgive my ignorance. Thank you for your time!
public
static
List
<
Subcategories
> GetSubcategories(
int
SubgroupID)
{
using
(
SqlConnection
connection =
new
SqlConnection
(
ConfigurationManager
.ConnectionStrings[
"XXX"
].ConnectionString))
{
using
(
SqlCommand
command =
new
SqlCommand
(
"GetSubcategories"
, connection))
{
command.CommandType =
CommandType
.StoredProcedure;
command.Parameters.Add(
new
SqlParameter
(
"@SubgroupID"
, SubgroupID));
connection.Open();
List
<
Subcategories
> list =
new
List
<
Subcategories
>();
using
(
SqlDataReader
reader = command.ExecuteReader())
{
while
(reader.Read())
{
Subcategories
temp =
new
Subcategories
(
(
int
)reader[
"SubCategoryId"
],
(
int
)reader[
"SubgroupID"
],
(
string
)reader[
"Title"
],
(
string
)reader[
"Manager"
],
(
string
)reader[
"Description"
]); <----- THIS LINE IS WHERE THE FAILUER OCCURS!
list.Add(temp);
}
}
return
list;
}
}
}
Reply
Answers (
1
)
File type associations
copy and paste function