c# - Check if datareader is empty -


this question has answer here:

i'm constant receive error:

additional information: data null. method or property cannot called on null values.

when try receive information. how can check if datareader empty.

for example code:

 while (rd.read())             {                 if (rd.hasrows)                 {                     foundinformation[0] = rd.getstring(0);                     foundinformation[1] = rd.getstring(1);                 }                 else                 {                     foundinformation[0] = "nvt";                     foundinformation[1] = "nvt";                 }                            } 

how can check if rd.getstring(0) empty?

thankyou.

you need call isdbnull before call getstring.

if (!rd.isdbnull(0)) {   //... } 

https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.isdbnull%28v=vs.110%29.aspx


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -