반응형
열린 MySqlDataReader
에서 NULL
값을 어떻게 확인할 수 있습니까?
다음은 작동하지 않습니다. 항상 else
를칩니다.
if (rdr.GetString("timeOut") == null)
{
queryResult.Egresstime = "Logged in";
}
else
{
queryResult.Egresstime = rdr.GetString("timeOut");
}
rdr.IsDbNull (int i)
은 이름이 아닌 열 번호 만 허용합니다.
해결 방법
var ordinal = rdr.GetOrdinal("timeOut");
if(rdr.IsDBNull(ordinal)) {
queryResult.Egresstime = "Logged in";
} else {
queryResult.Egresstime = rdr.GetString(ordinal);
}//if
또는
if(Convert.IsDBNull(rdr["timeOut"])) {
queryResult.Egresstime = "Logged in";
} else {
queryResult.Egresstime = rdr.GetString("timeOut");
}//if
참조 페이지 https://stackoverflow.com/questions/4739641
반응형
'MySql' 카테고리의 다른 글
MySQL Windows 7의 MySQL 5에서 쿼리 로그 활성화 (0) | 2020.10.21 |
---|---|
MySQL 여러 AND 문이있는 MySQL 쿼리가 하나를 무시하는 것 같습니다. (0) | 2020.10.21 |
MySQL 원격 데이터베이스에서 localhost outfile로 mysql 덤프 (0) | 2020.10.21 |
MySQL List of non-empty tables in MySQL database (0) | 2020.10.21 |
MySQL에서 innodb_lock_wait_timeout의 높은 값 (0) | 2020.10.21 |
댓글