c# - Form login information -



c# - Form login information -

i trying form place login info login pupil business relationship using id , password database code

how add together studentid , password form , execute?

here database :

student class:

class pupil : person { private int id; private string password; private string email; private double gpa; private string message; public student() : base() { this.id = 0; this.password = ""; this.email = ""; this.gpa = 0; } public student(int i, string pa, string em, int gp) : base() { this.id = i; this.password = pa; this.email = em; this.gpa = gp; insertdb(); } public student(int id) { selectdb(id); } //++++++++++++++++ database info elements +++++++++++++++++ public system.data.oledb.oledbdataadapter oledbdataadapter; public system.data.oledb.oledbcommand oledbselectcommand; public system.data.oledb.oledbcommand oledbinsertcommand; public system.data.oledb.oledbcommand oledbupdatecommand; public system.data.oledb.oledbcommand oledbdeletecommand; public system.data.oledb.oledbconnection oledbconnection; public string cmd; public void dbsetup() { // +++++++++++++++++++++++++++ dbsetup function +++++++++++++++++++++++++++ // dbsetup() method instantiates db objects needed access db, // including oledbdataadapter, contains 4 other objects(olsdbselectcommand, // oledbinsertcommand, oledbupdatecommand, oledbdeletecommand.) , each // command object contains connection object , sql string object. oledbdataadapter = new system.data.oledb.oledbdataadapter(); oledbselectcommand = new system.data.oledb.oledbcommand(); oledbinsertcommand = new system.data.oledb.oledbcommand(); oledbupdatecommand = new system.data.oledb.oledbcommand(); oledbdeletecommand = new system.data.oledb.oledbcommand(); oledbconnection = new system.data.oledb.oledbconnection(); oledbdataadapter.deletecommand = oledbdeletecommand; oledbdataadapter.insertcommand = oledbinsertcommand; oledbdataadapter.selectcommand = oledbselectcommand; oledbdataadapter.updatecommand = oledbupdatecommand; oledbconnection.connectionstring = "jet oledb:global partial mass ops=2;jet oledb:reg"+ "istry path=;jet oledb:database l" + "ocking mode=1;data source=c:\\registrationmdb.accdb;j" + "et oledb:engine type=5;provider=microsoft.jet.oledb.4.0;jet oledb:system datab" + "ase=;jet oledb:sfp=false;persist security info=false;extended properties=;mode=s" + "hare deny none;jet oledb:encrypt database=false;jet oledb:create scheme database=false;jet " + "oledb:don't re-create locale on compact=false;jet oledb:compact without replica repai" + "r=false;user id=admin;jet oledb:global mass transactions=1"; } public void selectdb(int id) { //++++++++++++++++++++++++++ select +++++++++++++++++++++++++ dbsetup(); cmd = "select * students id = " + id; oledbdataadapter.selectcommand.commandtext = cmd; oledbdataadapter.selectcommand.connection = oledbconnection; console.writeline(cmd); seek { oledbconnection.open(); system.data.oledb.oledbdatareader dr; dr = oledbdataadapter.selectcommand.executereader(); dr.read(); id=id; setpassword(dr.getvalue(1)+""); setemail(dr.getvalue(2)+""); setgpa(double.parse(dr.getvalue(3)+"")); } grab (exception ex) { console.writeline(ex); } { oledbconnection.close(); } } public void insertdb() { // +++++++++++++++++++++++++++ insert +++++++++++++++++++++++++++++++ dbsetup(); cmd = "insert students values(" + getid() + "," + "'" + getpassword() + "'," + "'" + getemail() + "'," + "'" + getgpa() + ")"; oledbdataadapter.insertcommand.commandtext = cmd; oledbdataadapter.insertcommand.connection = oledbconnection; console.writeline(cmd); seek { oledbconnection.open(); int n = oledbdataadapter.insertcommand.executenonquery(); if (n==1) console.writeline("data inserted"); else console.writeline("error: inserting data"); } grab (exception ex) { console.writeline(ex); } { oledbconnection.close(); } } public void updatedb() { //++++++++++++++++++++++++++ update +++++++++++++++++++++++++ cmd = "update students set id = '" + getid() + "'," + "password = '" + getpassword() + "', " + "email = '" + getemail() + "', " + "gpa = " + getgpa(); oledbdataadapter.updatecommand.commandtext = cmd; oledbdataadapter.updatecommand.connection = oledbconnection; console.writeline(cmd); seek { oledbconnection.open(); int n = oledbdataadapter.updatecommand.executenonquery(); if (n==1) console.writeline("data updated"); else console.writeline("error: updating data"); } grab (exception ex) { console.writeline(ex); } { oledbconnection.close(); } } public void deletedb() { //++++++++++++++++++++++++++ delete +++++++++++++++++++++++++ cmd = "delete students id = " + getid(); oledbdataadapter.deletecommand.commandtext = cmd; oledbdataadapter.deletecommand.connection = oledbconnection; console.writeline(cmd); seek { oledbconnection.open(); int n = oledbdataadapter.deletecommand.executenonquery(); if (n==1) console.writeline("data deleted"); else console.writeline("error: deleting data"); } grab (exception ex) { console.writeline(ex); } { oledbconnection.close(); } } public void setid(int id) { this.id = id; } public void setpassword(string password) { this.password = password; } public void setemail(string email) { this.email = email; } public void setgpa(double gpa) { this.gpa = gpa; } public int getid() { homecoming id; } public string getpassword() { homecoming password; } public string getemail() { homecoming email; } public double getgpa() { homecoming gpa; } public string getmessage() { homecoming this.message; } public void displays() { system.console.writeline("id = "+ getid()); system.console.writeline("password = "+ getpassword()); system.console.writeline("email = " + getemail()); system.console.writeline("gpa = " + getgpa()); } }

the form:

namespace students { public partial class studentlogin : form { public studentlogin() { initializecomponent(); } private void logingo_click(object sender, eventargs e) { } private void textbox1_textchanged(object sender, eventargs e) { } } }

in class add together boolean method check credentials of pupil

in class student.cs:

public string lognotification{get;set;} public bool confirmlogin(string id, string pw) { using(sqlconnection con = new sqlconnection("your connection string here")) { sqldataadapter da = new sqldataadapter(); dataset ds = new dataset(); sqlcommand cmd = new sqlcommand("select id, password students id = @id or password = @password",con); cmd.commandtype = commandtype.storedprocedure; cmd.parameters.add("@id", sqldbtype.varchar).value = id; cmd.parameters.add("@password", sqldbtype.varchar).value = pw; da.fill(ds); foreach (datarow dr in ds.tables[0].rows) { id = dr["@id"].tostring(); password = dr["@password"].tostring(); } if (id == id && password == pw) { homecoming true; } else { lognotification = "id/password incorrect"; homecoming false; } } }

in form:

private void logingo_click(object sender, eventargs e) { pupil st = new student(); if(st.confirmlogin(txtid.text,txtpass.text)==false) messagebox.show(st.lognotification); else //show next form or whatever action prefer }

c#

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -