i trying lookup employeeid 1 table based on windows login name, , use employeeid values table add them up. so, bill, employeeid 1 in tblemployees. sum noofhours in tbltimeavailable employeeid equals 1 , display on webpage. it's not working. can't figure out how search second table employeeid found in first table. (i'm rewriting code because of sql injection.)
dim windowsloginname system.string = httpcontext.current.user.identity.name 'system.security.principal.windowsidentity.getcurrent().name dim split string() = nothing dim vname string 'get network login name (name only) split = windowsloginname.split("\".tochararray) vname = split(1) dim connection string = "data source=willsql\ict2;initial catalog=timesql;integrated security=sspi" using con new sqlconnection(connection) dim sqlemp string = "select employeeid tblemployees login = @loginname" dim command new sqlcommand(sqlemp, con) con.open() rve = cmde.parameters.add(new sqlparameter {.parametername = "@loginname", .sqldbtype = sqldbtype.nvarchar, .value = vname}) end using when @ value of rve, it's giving me @loginname , not employeeid. fyi - there 1 row in tblemployees because each windows login name unique.
'get sick time using con new sqlconnection(connection) dim sqls1 string = "select sum(noofhours) total tbltimeavailable workcode = 1 , employeeid = @employeeid" dim command new sqlcommand(sqls1, con) con.open() rvsa = cmde.parameters.add(new sqlparameter {.parametername = "@employeeid", .sqldbtype = sqldbtype.nvarchar, .value = rve}) end using ' if sum equals 0, show 0 on webpage. if value, show value. if isdbnull(rvsa) rvsa = 0 textboxsa.text = 0 else textboxsa.text = rvsa.tostring end if i appreciate can give me!
you never executing command. after setting values of various parameters, need call 1 of execute methods on sqlcommand object. in case, since reading single value single row, can use executescalar method:
rve = command.executescalar()
Comments
Post a Comment