vb.net - how to get current row index when reading DbDataReader in ADO.net -
i have excel sheet read code this
public async function readrecordasync() task(of sellinglist) try dim sellings new sellinglist await conn.openasync() cmd = new oledbcommand() cmd.connection = conn cmd.commandtext = "select * [sheet1$]" dim reader = await cmd.executereaderasync() while reader.read() if checkemptyreader(reader) msgbox("first empty cell index = " & reader.depth) exit while end if dim x new buyableobject if not reader.isdbnull(0) x.name = reader.getstring(0) end if if not reader.isdbnull(1) x.soldcount = getintegervalue(reader(1).tostring) end if if not reader.isdbnull(2) x.sellingprice = getsinglevalue(reader(2).tostring) end if if not reader.isdbnull(3) x.originalprice = getsinglevalue(reader(3).tostring) end if x.updatecounts() if x.name isnot nothing sellings.add(x) end if end while reader.close() conn.close() return sellings catch ex exception msgbox(ex.tostring) return new sellinglist end try end function
and want current row index at
msgbox("first empty cell index = " & reader.depth)
but doesn't work , returns 0 , check empty reader :
public function checkemptyreader(reader dbdatareader) boolean if isdbnull(reader(0)) andalso isdbnull(reader(1)) andalso isdbnull(reader(2)) andalso isdbnull(reader(3)) return true else return false end if end function
so how current row index reader ?
i found simple solution adding simple counter
dim counter integer = 1 'start index while reader.read() if checkemptyreader(reader) msgbox("first empty row index = " & counter) exit while end if 'some code counter += 1 end while
Comments
Post a Comment