c# - Why am I getting 'Invalid attempt to read when no data is present' here? -
this question has answer here:
my stored procedure simple one-liner
create procedure checkiffinished @pid uniqueidentifier begin select finished partners id = @pid end and i'm calling c# code
using (sqlcommand cmd = new sqlcommand("checkiffinished", this._conn)) { cmd.commandtype = commandtype.storedprocedure; cmd.parameters.addwithvalue("@pid", pid); this._conn.open(); using (sqldatareader datareader = cmd.executereader()) { finished = datareader.getbyte(0) == 1 ? true : false; } this._conn.close(); } the column finished in partners table of type tinyint not null default 0
stack trace of error is
[invalidoperationexception: invalid attempt read when no data present.]
system.data.sqlclient.sqldatareader.checkdataisready(int32 columnindex, boolean allowpartiallyreadcolumn, boolean permitasync, string methodname) +6531242
system.data.sqlclient.sqldatareader.tryreadcolumn(int32 i, boolean settimeout, boolean allowpartiallyreadcolumn) +81
system.data.sqlclient.sqldatareader.readcolumn(int32 i, boolean settimeout, boolean allowpartiallyreadcolumn) +25
system.data.sqlclient.sqldatareader.getbyte(int32 i) +27
survey.models.surveydbmodel.checkiffinished(guid pid) +230
where going wrong here?
you forgot datareader.read().
until don't execute read() on data reader, data not available.
Comments
Post a Comment