String conversion to DBNull.Value
-
Hi, I tried the following function, but it doesn't want to work: //********************************************************************* // // CheckStringForDBNulls Static Method // // The CheckStringForDBNulls method checks if a string contains a value, if not it // returns DBNull.Value, or the value of the string. // //********************************************************************* public static DBNull CheckStringForDBNulls(string strCheckString) { if(strCheckString.Trim() != string.Empty) return strCheckString.Trim(); else return DBNull.Value; } Could you please let me know what I am doing wrong? This is used to check the parameter being added, if it contains nothing, the make the value DBNull.Value, or use the value of thr string. Thanks BRENDAN -- modified at 5:46 Thursday 20th October, 2005
-
Hi, I tried the following function, but it doesn't want to work: //********************************************************************* // // CheckStringForDBNulls Static Method // // The CheckStringForDBNulls method checks if a string contains a value, if not it // returns DBNull.Value, or the value of the string. // //********************************************************************* public static DBNull CheckStringForDBNulls(string strCheckString) { if(strCheckString.Trim() != string.Empty) return strCheckString.Trim(); else return DBNull.Value; } Could you please let me know what I am doing wrong? This is used to check the parameter being added, if it contains nothing, the make the value DBNull.Value, or use the value of thr string. Thanks BRENDAN -- modified at 5:46 Thursday 20th October, 2005
the return type of this method is DBNull, so you can only ever return a null value.. i suspect you don't really need a static method to perform this check, and could probably get away with something like this instead :
if(string.IsNullOrEmpty(strCheckString)) object = DBNull.Value; else object = strCheckString;
-
the return type of this method is DBNull, so you can only ever return a null value.. i suspect you don't really need a static method to perform this check, and could probably get away with something like this instead :
if(string.IsNullOrEmpty(strCheckString)) object = DBNull.Value; else object = strCheckString;
I want to put this into a function because I have a 20 checks, and the code can get very long. Please put the above mentioned code in a function.
-
I want to put this into a function because I have a 20 checks, and the code can get very long. Please put the above mentioned code in a function.
I don't know how well it would work but you could try making your method return
Object
-
I don't know how well it would work but you could try making your method return
Object
This was how I initially had it, I just thought there might be another way. But thanks for your help, I appreciate it!!