my if else statement in vb.net randomly displaying either of if or elseif condition made.
what i'm trying when datagridview checkbox selected , linklabel clicked, system row selected , update "edittime" column either "ds" or "en" depending on in column
so, if data in "edittime" column set "ds", if else condition should change "en" , vice versa.
dim en oledbcommand = new oledbcommand("select * [roster1]", myconnection) dim d oledbdatareader = en.executereader dim edt string = "" while d.read edt = d("edittime").tostring end while dim checkedrows = ( rows in admintabdisplay.rows.cast(of datagridviewrow)() cbool(rows.cells("ck").value) = true ).tolist if checkedrows.count > 0 dim sb new system.text.stringbuilder each row datagridviewrow in checkedrows sb.appendline(row.cells("employee id").value.tostring) next if edt = "ds" dim st string = sb.tostring dim value integer = cint(st) dim cmd oledbcommand = new oledbcommand("update [roster1] set [edittime] = @pw [employee id] = @v", myconnection) cmd.parameters.addwithvalue("@pw", "en") cmd.parameters.addwithvalue("@v", value) cmd.executenonquery() msgbox("edit enabled!") elseif edt = "en" dim st string = sb.tostring dim value integer = cint(st) dim cmd oledbcommand = new oledbcommand("update [roster1] set [edittime] = @pw [employee id] = @v", myconnection) cmd.parameters.addwithvalue("@pw", "ds") cmd.parameters.addwithvalue("@v", value) cmd.executenonquery() msgbox("edit disabled!") end if
this code. yet, output seems bit randomized.
how many rows in [roster1] table? because statements:
while d.read edt = d("edittime").tostring end while
in edt have value of last row. correct?
edit:
try code:
dim checkedrows = ( rows in admintabdisplay.rows.cast(of datagridviewrow)() cbool(rows.cells("ck").value) = true ).tolist if checkedrows.count > 0 each row datagridviewrow in checkedrows dim st string = row.cells("employee id").value.tostring dim value integer = cint(st) dim en oledbcommand = new oledbcommand("select * [roster1] [employee id] = @v", myconnection) cmd.parameters.addwithvalue("@v", value) dim d oledbdatareader = en.executereader dim edt string = d("edittime").tostring if edt = "ds" dim cmd oledbcommand = new oledbcommand("update [roster1] set [edittime] = @pw [employee id] = @v", myconnection) cmd.parameters.addwithvalue("@pw", "en") cmd.parameters.addwithvalue("@v", value) cmd.executenonquery() msgbox("edit enabled!") elseif edt = "en" dim st string = sb.tostring dim value integer = cint(st) dim cmd oledbcommand = new oledbcommand("update [roster1] set [edittime] = @pw [employee id] = @v", myconnection) cmd.parameters.addwithvalue("@pw", "ds") cmd.parameters.addwithvalue("@v", value) cmd.executenonquery() msgbox("edit disabled!") end if next
edit (i added while loop in , edited variables , works!):
dim checkedrows = ( rows in admintabdisplay.rows.cast(of datagridviewrow)() cbool(rows.cells("ck").value) = true ).tolist if checkedrows.count > 0 each row datagridviewrow in checkedrows dim st string = row.cells("employee id").value.tostring dim value integer = cint(st) dim en oledbcommand = new oledbcommand("select * [roster1] [employee id] = @v", myconnection) en.parameters.addwithvalue("@v", value) dim d oledbdatareader = en.executereader dim edt string = "" while d.read edt = d("edittime").tostring end while if edt = "ds" dim cmd oledbcommand = new oledbcommand("update [roster1] set [edittime] = @pw [employee id] = @v", myconnection) cmd.parameters.addwithvalue("@pw", "en") cmd.parameters.addwithvalue("@v", value) cmd.executenonquery() msgbox("edit enabled!") elseif edt = "en" dim cmd oledbcommand = new oledbcommand("update [roster1] set [edittime] = @pw [employee id] = @v", myconnection) cmd.parameters.addwithvalue("@pw", "ds") cmd.parameters.addwithvalue("@v", value) cmd.executenonquery() msgbox("edit disabled!") end if next end if
Comments
Post a Comment