i making stored procedure call 2 parameters using idatareader. when trying read values, throws me invalid attempt call fieldcount when reader closed. error. neither i'm closing connection nor using using. not sure why getting error. in immediate window don't see reader.hasrows property when debugging, can see results while making call when want read it, throws error.
code:
public bool uniquecolumnvaluescheckcall(observablecollection<string> selectedcolumns, string selectedtablename) { bool uniquevalueexists = true; string columns = string.empty; string result = string.empty; if (selectedcolumns != null && selectedcolumns.count > 0) columns = string.join(", ", selectedcolumns); int commandtimeout = getsqlcommandtimeout(); idataparameter[] parameters = { this.helper.getparameter("@columnname", columns), this.helper.getparameter("@tablename", selectedtablename) }; //i can see results while debugging. idatareader reader = this.helper.withcommandtimeout(commandtimeout).executereader(this.connectionstring, "ix_finduniquecolumnvalues", parameters); try { while (reader.read()) // reason throws error "invalid attempt call fieldcount when reader closed." here { if (!reader.isdbnull(0)) result = reader.getstring(0); if (result.equals("selected columns have no unique values")) uniquevalueexists = false; else uniquevalueexists = true; } } catch (exception) { throw; } return uniquevalueexists; }
Comments
Post a Comment