Click here to Skip to main content
14,692,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have tried the code which is mentioned in below ,even i was not able to find what is the issue .(Select query working fine after am not able to fetch the username and password for next windows.
I hope clarify the issue ,if you didn't get let me know

I am new in MFC if anyone help its will be appreciated

Thank you advance!

What I have tried:

 UpdateData();
     CDatabase database;
     CString SqlString;
     CString sDsn;
     CString sDriver = L"MICROSOFT ACCESS DRIVER (*.mdb, *.accdb)";
     CString sFile = L"G:\\manju\\wfh\\rock.accdb";
    
   sDsn.Format(L"ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile);
 TRY{
  database.Open(NULL,false,false,sDsn);
  CRecordset recset( &database );
  
  SqlString.Format(_T("SELECT *FROM new WHERE UserID ='%s' and Password = '%s' ", m_user,m_password));
  recset.Open(CRecordset::forwardOnly,SqlString,CRecordset::readOnly);
  
  if(!recset) // HERE I AM FACING ISSUE 
  {
     AfxMessageBox (L" Login Suucessfully ");
    thrdlg dil;
//	  dil.DoModal();

  }
  else
  {
     AfxMessageBox(L" UserID and Password is wrong!! ");
  }

  database.Close();
 }
Posted
Updated 29-Jun-20 23:14pm

1 solution

if(!recset) // HERE I AM FACING ISSUE 
  {
     AfxMessageBox (L" Login Suucessfully ");
    thrdlg dil;
//	  dil.DoModal();

  }
  else
  {
     AfxMessageBox(L" UserID and Password is wrong!! ");
  }

Firstly the logic of your if statement is wrong; if the recset object exists you post the error message. And secondly, and more importantly, you are ignoring the actual return value from the Open call. You need to capture the result of the Open call and test that. So your code should be:
bool bSuccess = recset.Open(CRecordset::forwardOnly,SqlString,CRecordset::readOnly);
if (bSuccess)
{
     AfxMessageBox (L" Login Suucessfully ");
    thrdlg dil;
//	  dil.DoModal();
  }
  else
  {
     AfxMessageBox(L" UserID and Password is wrong!! ");
  }
   
Comments
Member 14837073 30-Jun-20 5:33am
   
"unhandeled exception at 0x6a112efo (msvcr90d.dll) in kgf .exe : 0xc0000005: Access vilotaion reading location 0x8370c29c "
i geting this error
Richard MacCutchan 30-Jun-20 5:38am
   
You have an invalid address somewhere, which usually results from an uninitialised pointer. Use the debugger to step through the code to find out where it occurs, and which address is not valid.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900