c# - COM object that has been separated from its underlying RCW cannot be used? -


setting aside salt , hash debate. , please reply if know answer.

i trying create method user enters credentials date , times recorded automatically when logging in , out.

i have 2 problems

problem 1 - have created simple method logging in , out. when included date , time code noted these recorded , stored users. have 2 users. if 1 user logins date , time recorded , stamp other user.

problem 2 - second problem subject headers says error message when update command parameter in same method select.

if me grateful both of problems. minor issue? if omitting date , time grateful if me on multi login function.

access 2003 ~ 2 tables. table 1 - named logintable table 2 - named loginlogtable

logintable

fieldname datatype

username   text password   text  loginlogtable fieldname     datatype usernameid    text username      text loggedin      date/time loggedintime  date/time          private void btnlogin_click(object sender, eventargs e)  {     using (var command = mycon.createcommand())         {             command.commandtext = "select username, password logintable where strcomp(username, @username,0) = 0 , strcomp(password, @password,0)=0";            command.parameters.addwithvalue("username", (txtusername.text));             command.parameters.addwithvalue("password", (txtpassword.text));             mycon.open();              var reader = command.executereader();             {                 if (reader.hasrows)                 {                     messagebox.show("login successful");                     form2 frm = new form2();                     frm.show();                     while (reader.read())                     {                       txtusername.text = reader["username"].tostring();                       txtpassword.text = reader["password"].tostring();                     }                      oledbcommand cmd = new oledbcommand();                     cmd.connection = mycon;                       cmd.commandtext = "update [loginlogtable] set [loggedindate] = ?, [loggedintime] = ?";                       cmd.parameters.addwithvalue("@loggedindate", datetime.now.toshortdatestring());                     cmd.parameters.addwithvalue("@loggedintime", datetime.now.tostring("hh:mm"));                     cmd.executenonquery();                     mycon.close();                  }             else messagebox.show("login falied");             }          }            mycon.close();            mycon.close(); 

}

you don't have condition in update query, update records in table. add condition update single record. don't know have in table, this:

cmd.commandtext = "update [loginlogtable] set [loggedindate] = ?, [loggedintime] = ? username = ?"; cmd.parameters.addwithvalue("loggedindate", datetime.now.toshortdatestring()); cmd.parameters.addwithvalue("loggedintime", datetime.now.tostring("hh:mm")); cmd.parameters.addwithvalue("username", txtusername.text); 

you should close , dispose first data reader , command before executing second command.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -