c# - Datareader.HasRow is wrong -
can confirm or dispute problem i'm having accessing accdb database datareader. setup datareader , query database. when check datareader.hasrows, true, no matter if records present or not.
i've double verified data table empty, no records @ all, datareader.hasrows still says got records.
if go on , try datareader.read, when know there no records returned, error saying "no data exists row/column." expected.
has seen before? or can doesn't happen?
thanks
sql = @"select a.license, a.classid, a.currentlyin, a.totalscans " + @"from attendance " + @"where a.license = " + myscan.licenseint + @" , a.classid = " + myscan.classid + ";"; _parent.statusoutput(sql); cmddb = new oledbcommand(sql, cndb); try { //cndb.open(); drdb = cmddb.executereader(); if (drdb.hasrows) { _parent.statusoutput("data reader has no rows"); } else { _parent.statusoutput("data reader has rows."); drdb.read(); _parent.statusoutput(drdb["license"].tostring() + ", " + drdb["classid"].tostring()); } there go. sorry confusion on how post this.
in sample code here if reader has rows prints error
and if reader not have rows prints has , reads , throws exception
swap:
if (drdb.hasrows) { _parent.statusoutput("data reader has rows."); drdb.read(); _parent.statusoutput(drdb["license"].tostring() + ", " + drdb["classid"].tostring()); } else { _parent.statusoutput("data reader has no rows"); }
Comments
Post a Comment