joeybagadonutz Posted April 21, 2004 Posted April 21, 2004 Hi, I have this code that runs inside of a loop: While nDataReader.Read() strNewSnow = nDataReader!New_snow_24 strBaseDepth = nDataReader!Base_depth strTopDepth = nDataReader!top_depth strConditions = nDataReader!Conditions End While This works great, but if the value in the database is NULL, it craps out because it tries to set my string variable to null. If I use the debugger I can step through it and its all fine, but soon as i hit the null value it errors. What is the best most efficient way to deal with this? I don't have to go through and put in a bunch of if statements do I? thanks. -JBD Quote
wessamzeidan Posted April 21, 2004 Posted April 21, 2004 You can use the isDbNull() method to check if the value is null and then set the value of the string Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
joeybagadonutz Posted April 21, 2004 Author Posted April 21, 2004 So, the only way I can do this is like this? nDataReader = comSQL.ExecuteReader(CommandBehavior.CloseConnection) While nDataReader.Read() If IsDBNull(nDataReader!New_snow_24) Then strNewSnow = "" Else strNewSnow = nDataReader!New_snow_24 End If If IsDBNull(nDataReader!Base_depth) Then strBaseDepth = "" Else strBaseDepth = nDataReader!Base_depth End If If IsDBNull(nDataReader!top_depth) Then strTopDepth = "" Else strTopDepth = nDataReader!top_depth End If If IsDBNull(nDataReader!Conditions) Then strConditions = "" Else strConditions = nDataReader!Conditions End If End While Yuck :) there is A LOT of these, kinda a pain :) Quote
joeybagadonutz Posted April 21, 2004 Author Posted April 21, 2004 What if I didnt use a datareader, and used a dataset instead? would it still error when I set the string to like ds.tables(0).rows(0).item("fldMyField") and it was NULL? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.