Click here to Skip to main content
15,910,773 members
Home / Discussions / Database
   

Database

 
GeneralRe: Stored Proc StartValue and EndValue [modified] Pin
ASPnoob1-Aug-07 20:53
ASPnoob1-Aug-07 20:53 
GeneralRe: Stored Proc StartValue and EndValue Pin
_Damian S_2-Aug-07 1:58
professional_Damian S_2-Aug-07 1:58 
QuestionHelp me Pin
maram20001-Aug-07 13:56
maram20001-Aug-07 13:56 
AnswerRe: Help me Pin
Christian Graus1-Aug-07 14:55
protectorChristian Graus1-Aug-07 14:55 
AnswerRe: Help me Pin
Paul Conrad1-Aug-07 16:36
professionalPaul Conrad1-Aug-07 16:36 
QuestionConvert to Stored Proc [modified] Pin
ASPnoob1-Aug-07 10:44
ASPnoob1-Aug-07 10:44 
AnswerRe: Convert to Stored Proc Pin
Mike Dimmick1-Aug-07 11:42
Mike Dimmick1-Aug-07 11:42 
QuestionHandling null values with SqlDataReader Pin
eggie51-Aug-07 7:24
eggie51-Aug-07 7:24 
See the below C# snippet that's itterating over a SqlDataReader:

while (reader.Read())
           {
               c.ID = reader.GetInt32(0);
               c.Category.ID = reader.GetInt32(1);
               c.Subject = reader.GetString(2).Trim();
               c.Body = reader.GetString(3).Trim();
               c.SourceVideoClip = reader.GetString(4).Trim();
               c.StillImage = reader.GetString(5).Trim();
               c.Notes = reader.GetString(6).Trim();
               c.UploadTime = reader.GetDateTime(7);
               c.AdID = reader.GetInt32(8);
               c.ValidAfter = reader.GetDateTime(9);
               c.InvalidAfter = reader.GetDateTime(10);
               c.BillingCode = reader.GetInt32(11);
               c.Name= reader.GetString(12).Trim();
               c.Birth = reader.GetDateTime(13);
               c.Category.Name = reader.GetString(14);
           }


Everything runs fine until it gets to reader.GetString(4).Trim();, which is null, so it throws an SqlNullValueException exception.

How can I gracefully handle these null values. It seems GetString & GetInt just throw exceptions when they encounter null values. I guess the solution I'm looking for would return null or 0 for a db null value.

How am I supposed to deal with this. Do I have to put if statements around each GetXX to check if it's null?


/\ |_ E X E GG

AnswerRe: Handling null values with SqlDataReader Pin
Pete O'Hanlon1-Aug-07 9:05
mvePete O'Hanlon1-Aug-07 9:05 
AnswerRe: Handling null values with SqlDataReader Pin
Pete O'Hanlon1-Aug-07 9:31
mvePete O'Hanlon1-Aug-07 9:31 
GeneralRe: Handling null values with SqlDataReader Pin
eggie51-Aug-07 18:46
eggie51-Aug-07 18:46 
AnswerRe: Handling null values with SqlDataReader Pin
Mike Dimmick1-Aug-07 11:48
Mike Dimmick1-Aug-07 11:48 
GeneralRe: Handling null values with SqlDataReader Pin
Pete O'Hanlon2-Aug-07 10:02
mvePete O'Hanlon2-Aug-07 10:02 
Questionsql 2005 not installing [modified] Pin
costavo1-Aug-07 2:35
costavo1-Aug-07 2:35 
AnswerRe: sql 2005 not installing Pin
originSH1-Aug-07 2:47
originSH1-Aug-07 2:47 
QuestionSQL 2000 & 2005 Pin
Saranya B1-Aug-07 1:39
Saranya B1-Aug-07 1:39 
AnswerRe: SQL 2000 & 2005 Pin
kubben1-Aug-07 2:13
kubben1-Aug-07 2:13 
Questionauto run a query in ms sqlserver Pin
asdf17531-Aug-07 1:19
asdf17531-Aug-07 1:19 
AnswerRe: auto run a query in ms sqlserver Pin
Pete O'Hanlon1-Aug-07 2:21
mvePete O'Hanlon1-Aug-07 2:21 
QuestionBenefits of Access 2007 Pin
Jason Stamp31-Jul-07 23:23
Jason Stamp31-Jul-07 23:23 
AnswerRe: Benefits of Access 2007 Pin
Aaron VanWieren1-Aug-07 4:24
Aaron VanWieren1-Aug-07 4:24 
QuestionCreating Stored Proc in Text Editor [modified] Pin
ASPnoob31-Jul-07 21:17
ASPnoob31-Jul-07 21:17 
AnswerRe: Creating Stored Proc in Text Editor Pin
originSH31-Jul-07 22:10
originSH31-Jul-07 22:10 
QuestionNested Select statement Pin
Prakash_Mishra31-Jul-07 20:34
Prakash_Mishra31-Jul-07 20:34 
AnswerRe: Nested Select statement Pin
kubben1-Aug-07 2:18
kubben1-Aug-07 2:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.