Home > Software engineering >  Based on the MFC database ADO parameter query string type error
Based on the MFC database ADO parameter query string type error

Time:10-08

 

_ConnectionPtr m_pconnection;
_RecordsetPtr m_precordset;
_CommandPtr m_command;
ParametersPtr * Params1=NULL;
_ParameterPtr paramet1;
Cstrings name;
The UpdateData (TRUE);

Try
{
M_pconnection. CreateInstance (" ADODB. Connection ");
M_pconnection - & gt; The ConnectionString="Provider=SQLOLEDB. 1; Integrated Security=SSPI; Persist Security Info=False; Initial Catalog=master; Data Source=QH - 20160810 ZMWN \ \ SQLEXPRESS ";
Retrieves the hr=m_pconnection - & gt; Open (" ", ""," ", adModeUnknown);
If (SUCCEEDED (hr))
{
Retrieves documents (=m_command. CreateInstance (__uuidof (Command));
M_precordset. CreateInstance (__uuidof (you));

M_command - & gt; ActiveConnection=m_pconnection;
M_command - & gt; CommandText=_bstr_t (_T (" select * from studentinfo where stuno=@ stuno "));//stuno is defined as an int type
Paramet1=m_command - & gt; CreateParameter (_bstr_t (_T (" ")), adVarChar, adParamInput, 2, _variant_t (_T (" 5 ")));
Paramet1 - & gt; Value=https://bbs.csdn.net/topics/_variant_t (_T (" 5 "));
Int ff=0;
M_command - & gt; The Parameters - & gt; Append (paramet1);
M_precordset - & gt; Open ((IDispatch *) m_command, vtMissing, adOpenStatic adLockOptimistic, adCmdText);

while (! M_precordset - & gt; AdoEOF)
{
Edit_stuNo=(WCHAR *) _bstr_t (m_precordset - & gt; Stuno GetCollect (" "));
Edit_stuName=(WCHAR *) _bstr_t (m_precordset - & gt; GetCollect (" stuname "));
The UpdateData (false);
M_precordset - & gt; MoveNext ();

}
}
}
Catch _com_error (e)
{
Cstrings errormessage;
Errormessage. The Format (_T (" connect to database failure! The \ r \ n error message: % s "), (LPCTSTR) e.D escription ());
AfxMessageBox (errormessage);
}
appeared the wrong answer thank you

CodePudding user response:

SQL statement error, first in view of the general statements, again into the code, @ stuno variable is not defined

CodePudding user response:

Is that a parameter is not variable, should need not defined

CodePudding user response:

Run the SQL statement alone feasible?

CodePudding user response:

I can't, just now I put the list of stuno is defined as an int type, then the

CodePudding user response:

Such written can be passed

CodePudding user response:

Is solved, I get complicated

CodePudding user response:

Wrong is not a code, is a database SQL statement
  • Related