vb.net - SELECT UPDATE SQL Not Working -
i have 2 forms
first form has
public class frmmain friend strbillidnumber string friend strbillpassword string friend ds new dataset friend cnn oledbconnection friend sql string friend adptr oledbdataadapter dim attempt integer = 1 private sub btnsign_click(sender object, e eventargs) handles btnsign.click dim connectionstring string connectionstring = "provider=microsoft.ace.oledb.12.0;data source=c:\users\renz\documents\visual studio 2012\final\database\usersdb.accdb;" sql = "select id, lastname, firstname, loginstatus tbluser" cnn = new oledbconnection(connectionstring) try cnn.open() adptr = new oledbdataadapter(sql, cnn) adptr.fill(ds) = 0 ds.tables(0).rows.count - 1 if ds.tables(0).rows(i).item(0) = txtid.text messagebox.show("username matched") if ds.tables(0).rows(i).item(1) = txtpassword.text messagebox.show("password matched") if txtpassword.text = "admin" messagebox.show("you logged in admin.") frmfaculty.show() me.hide() else frmstudent.lblsi.text = ds.tables(0).rows(i).item(0) frmstudent.lblln.text = ds.tables(0).rows(i).item(1) frmstudent.lblfn.text = ds.tables(0).rows(i).item(2) frmstudent.lblls.text = ds.tables(0).rows(i).item(3) messagebox.show("you logged in.") frmstudent.show() me.hide() end if else messagebox.show("invalid password.") messagebox.show("please try again." & vbnewline & "attempt: " & attempt & " out of 3") attempt = attempt + 1 end if end if next adptr.dispose() cnn.close() catch ex exception messagebox.show("please try again!") end try 'log-in attempt 3x fail' if attempt > 3 messagebox.show("you have exceeded number of login attempt." & vbnewline & "please contact administrator.") end if end sub
and second form has
imports system.data.oledb public class frmstudent dim timeinhold string private sub loginbtn_click(sender object, e eventargs) handles loginbtn.click dim cnn2 new oledbconnection dim command oledbcommand dim integer dim sql2 string dim status string try cnn2 = new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=c:\users\renz\documents\visual studio 2012\final\database\auditdb.mdb;") cnn2.open() sql2 = "insert audit ([id],[timein]) values('" & frmmain.txtid.text & "','" & datetime.now & "')" command = new oledbcommand(sql2, cnn2) = command.executenonquery catch ex exception cnn2.close() end try messagebox.show("you have signed in." & vbnewline & " please don't forget logout.") frmmain.cnn = new oledbconnection("provider=microsoft.ace.oledb.12.0;data source=c:\users\renz\documents\visual studio 2012\final\database\usersdb.accdb;") frmmain.cnn.open() frmmain.adptr = new oledbdataadapter(frmmain.sql, frmmain.cnn) frmmain.adptr.fill(frmmain.ds) if frmmain.ds.tables(0).rows(i).item(0) = lblsi.text frmmain.sql = "update tbluser set loginstatus = 'signedin'" frmmain.cnn.close() end if me.close() frmmain.show() frmmain.txtid.text = string.empty frmmain.txtpassword.text = string.empty end sub
i can't select , update sql statement work data set form 1. , when button clicked, update field "loginstatus" value of "signed in".
p.s. i'm creating time-in, time-out monitoring system determine if user admin or student , redirect them corresponding forms. student form have sign in , sign out buttons, , record time in , time out. when sign in clicked, grayed out.
please help..
i think missing executenonquery in second form , there 1 user query fine if more 1 consider using " clause" eg.
sql= "update tbluser set loginstatus = 'signedin' id =" <provide id>
if doesn't solve problem feel free ask more.
regards.
Comments
Post a Comment