Home > Software engineering >  I'm a newcomer who I'm afraid, determine the user login, then write the code can not imple
I'm a newcomer who I'm afraid, determine the user login, then write the code can not imple

Time:10-13

HTML code is as follows, by the way, please down to me to check the wrong, head all big, can't figure out where is wrong, compiled through, just can appear the run time error!

 the UpdateData (true); 
If (m_usename. IsEmpty () | | m_password. IsEmpty ())
{
MessageBox (" account and password cannot be empty!" , "tip");
}
M_pConnection. CreateInstance (" ADODB. Connection ");
M_pConnection - & gt; ConnectionTimeout=5;
M_pConnection - & gt; The ConnectionString="Provider=SQLOLEDB. 1; Persist Security Info=False; \
User ID=sa; Initial Catalog=lyelcn; Data Source=USER - 20160310 qy \ \ INST1 ";
Retrieves the hr;
Hr=m_pConnection - & gt; Open (_T (" "), _T (" "), _T (" 12345 "), adConnectUnspecified);
If (FAILED (hr))
{
MessageBox (" database connection failed!" , "tip");
return;
}
Try {hr=m_pRecordset. CreateInstance (" ADODB. You "); }
The catch (... ) {AfxMessageBox (" data set to build failure!" ); }

Bool found=false;
Cstrings username;
Cstrings password;
While (m_pRecordset - & gt; AdoEOF)
{
The username=(char *) (_bstr_t) m_pRecordset - & gt; Yonghuming GetCollect (" ");
Password=(char *) (_bstr_t) m_pRecordset - & gt; GetCollect (" mima ");
If (password==m_password & amp; & The username==m_usename)
{
Found=true;
break;
}
M_pRecordset - & gt; MoveNext ();
}
If (found)
{AfxMessageBox (" login success "); }
The else
{AfxMessageBox (" login failed "); }
M_pRecordset - & gt; Close ();

CodePudding user response:

You hit a breakpoint, then place the order with the Debug mode step F10, was clear to see which function calls failed not ~

CodePudding user response:

You can't write a SQL statement, directly to judge if there is any user name m_usename, password for m_password records exist, so it is ok to return a result,

Give it a try, statements for all database operations, increase the try, catch, catch catch _com_error, check the _com_error useful error message,

CodePudding user response:

Thinking very alternative, why not use an SQL query, but the each record in the recordset compared one by one and input, so not tired

CodePudding user response:

Is one step closer to the abnormal, mostly cause the program to exit the

In the first lines of code you provide under press F9 breakpoints, and then press F5 to debug to run the program, broken down, one step to run the program, see where an error.

CodePudding user response:

Without the SQL query, there will be a data record set
  • Related