i insert row of interest each customer @ end of each month after checking same. working first 1 not rest. i'm clueless how use 'for..each' here... :|
any appreciated.
thanks!
dim str(0) string str(0) = getid("transactions", "id") dim tempstr(5) string try conn.open() com.commandtext = "select * customer" dr = com.executereader while dr.read() tempstr(0) = dr(0).tostring tempstr(1) = dr(2).tostring tempstr(2) = dr(3).tostring tempstr(3) = dr(5).tostring tempstr(4) = dr(6).tostring tempstr(5) = dr(7).tostring dim lastintdate = dateadd("m", 0, dateserial(year(today), month(today), 0)) try com.commandtext = "select * transactions cid=" & tempstr(0).tostring & " , tdate=#" & lastintdate & "# , description='interest'" dr2 = com.executereader if dr2.read = true dr2.close() else try com.commandtext = "insert transactions values(?,?,?,?,?,?,?)" com.parameters .add("@id", oledb.oledbtype.varchar).value = str(0).tostring .add("@custid", oledb.oledbtype.varchar).value = tempstr(0).tostring .add("@tdate", oledb.oledbtype.date).value = date.today .add("@credit", oledb.oledbtype.currency).value = 0 .add("@debit", oledb.oledbtype.varchar).value = 500 .add("@balance", oledb.oledbtype.varchar).value = val(tempstr(3) + interest) .add("@desc", oledb.oledbtype.varchar).value = "interest" end com.executenonquery() com.parameters.clear() catch ex exception msgbox(ex.message) end try try com.commandtext = "update customer set currbal=? id=?" com.parameters .add("@currbal", oledb.oledbtype.varchar).value = (tempstr(3) + interest) .add("@custid", oledb.oledbtype.varchar).value = tempstr(0).tostring end com.executenonquery() com.parameters.clear() catch ex exception msgbox(ex.message) end try end if dr2.close() catch ex exception end try end while dr.close() catch ex exception msgbox(ex.message) end try conn.close()
you close. don't want dr.read
while false, want read while true. typically just:
do while dr.read()
ok, think doing work, not using proper dispose pattern , using sql injection vulnerable implementation, answer question:
the reason works first customer read first record dr
. bad practices aside, this:
dim str(0) string str(0) = getid("transactions", "id") dim tempstr(5) string try conn.open() com.commandtext = "select * customer" dr = com.executereader while dr.read() tempstr(0) = dr(0).tostring tempstr(1) = dr(2).tostring tempstr(2) = dr(3).tostring tempstr(3) = dr(5).tostring tempstr(4) = dr(6).tostring tempstr(5) = dr(7).tostring '********************** ' other stuff goes here executes once ' each customer '********************** end while dr.close() catch ex exception msgbox(ex.message) end try
Comments
Post a Comment