Horje
C# datareadeer return null Code Example
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.




Csharp

Related
c# if statement with 2 conditions Code Example c# if statement with 2 conditions Code Example
c# foreach Code Example c# foreach Code Example
orElseThrow Code Example orElseThrow Code Example
Cause BSOD C# Code Example Cause BSOD C# Code Example
speedtest.net cli Code Example speedtest.net cli Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11