Try txtMiddleName. Text = rdrGetUserInfo. IsDBNull(1)?"" : rdrGetUserInfo.
GetString(1).
2 Is it me or does anyone else hate "", use String. Empty its cleaner. More .net.
– JonH Mar 22 '10 at 14:53 Works perfectly Mark. Also using String. Empty (thanks JonH) – user279521 Mar 22 '10 at 15:03.
You can use the IsDBNull method on the DataReader. If (!rdrGetUserInfo. IsDBNull(1)) { txtMiddleName.
Text = rdrGetUserInfo. GetString(1); }.
It's because the rdrGetUserInfo is returning DBNull which is a class. Before getting the string do a check for dbnull it's something like (been a while since I used one! ): if (!rdrGetUserInfo.
IsDBNull("someField")) txtMiddleName. Text = rdrGetUserInfo. GetString(1).
If(rdr("Field") == DBNull. Value) 'assign String. Empty myString = string.
Empty; else 'assign value myString = rdr("Field"); Or to shorten this up you could do this: txtMiddleName. Text = rdrGetUserInfo. IsDBNull(1)?String.
Empty : rdrGetUserInfo. GetString(1).
You should check the column for DbNull before calling GetString.
IsDbNull(int) is usually much slower that using methods like GetSqlInt32 and then comparing to DBNull. Value or using it's own . IsNull Like: public static int Int32(this SqlDataReader r, int ord) { var t = r.
GetSqlInt32(ord); return t. IsNull? Default(int) : t.
Value; } Tried a few template solutions but to no avail so far. The problem is that all Sql-types (SqlInt32 here) types are actually structs and while they all have . Value property C# doesn't have real templates to handle that.
Also they have their own INullable interface which has only . IsNull and is not conpatible with Nyllable. I suspect that one would need full set of Sql-types as C# templates or to add ICOnvertible to them in order to be able to have just one or two templated methods.
If someone has maybe an idea with a functional trick or two speak up :-).
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.