sql server ce - C# - Multiple Users from SQL Database for Login Form -


so, have loginform user has login go mainform. have database table created store usernames , passwords, logging in application.

if user types in correct username , password , clicks login, should take him/her mainform. know how do, how usernames , passwords sql database , check if exist, , if exist, correct username correct password or vice versa?

like said, created sql database store usernames , passwords. saved user username , password both "admin", testing purposes.

i tried following code, isn't letting me log in though typed correct username , password.

string username; string password;  private void btnlogin_click(object sender, eventargs e) {     try     {         sqlceconnection con = new sqlceconnection(@"connectionstring");         sqlcecommand com = new sqlcecommand("select username, password userspass username = '" + txtusername.text + "' , password = '" + txtpassword.text + "'", con);         con.open();      if (con.state == connectionstate.open)     {         sqlcedatareader dtr = com.executereader();          while (dtr.read())         {             username = dtr["username"].tostring();             password = dtr["password"].tostring();             if (username == txtusername.text && password == txtpassword.text)             {                 mainform frm = new mainform();                 frm.show();                 this.hide();                  }             else             {                 messagebox.show("invalid credentials!\nplease enter valid username , password continue.", "login error", messageboxbuttons.ok, messageboxicon.error);             }         }     }     }     catch (exception)     {         messagebox.show("erorr", "error");     } } 

forgive me if i'm missing obvious, i'm new c#. thank in advance.

you getting error message. start giving more information on that. either place breakpoint in

catch (exception) {     messagebox.show("erorr", "error"); } 

so can see details on exception or change to

catch (exception ex) {     messagebox.show("erorr", ex.message + environment.newline + ex.stacktrace); } 

that give details on why application failing , set on path towards getting things working want.

i suspect have bad connection string.

edit: particular issue caused sql server compact edition references being used in place of standard edition references. see comments.


Comments