C# datareadeer return null
// ****** Use MySqlDataReader instead of SqlReader if you are using MySQL *******
//You need to check for IsDBNull:
//That's your only reliable way to detect and handle this situation.
//I wrapped those things into extension methods and tend to return a default value
//if the column is indeed null:
public static string SafeGetString(this SqlDataReader reader, int colIndex)
{
if(!reader.IsDBNull(colIndex))
return reader.GetString(colIndex);
return string.Empty;
}
//Now you can call it like this:
employee.FirstName = SqlReader.SafeGetString(indexFirstName);
// and you'll never have to worry about an exception or a null value again.
Also in C#:
- page parent wpf
- file picker uwp c#
- unity add component
- how to find object by ag unity
- How can you learn C# on your own
- c# object to json string
- c# write to console
- orderby make sunday last day c#
- generate range c#
- how to get object to spawn in a curcle
- c# if statement
- c# new list object
- for c#
- solid principles c#
- c# remove from list in foreach
- edit bool from diffirent script
- import regex c#
- unity load text resources from subfolder
- unity set sprite transparency
- dto and automapper
- how to store some variables on the device in unity
- matplotlib measure the width of text
- how to use K2 games Games parallax background
- what function is called just before the a script is ended c#