Home > Software engineering >  @ @ ROWCOUNT how to read? SQL execution results @ @ ROWCOUNT how to read in the MFC project
@ @ ROWCOUNT how to read? SQL execution results @ @ ROWCOUNT how to read in the MFC project

Time:11-20

SQL execution results @ @ ROWCOUNT how to read in the MFC project? The code is as follows:

 if ((select count (*) from mydb. The dbo. TestTB where name='test')=0) 
Insert into mydb. Dbo. TestTB (name, memo) VALUES (' test ', 'test data')

Select @ @ ROWCOUNT tempcnt


 this="if ((select count (*) from mydb. The dbo. TestTB where name='test')=0) insert into mydb. The dbo. TestTB (name, memo) VALUES (' test ', 'test data') select @ @ ROWCOUNT tempcnt"; 

Try
{
M_pRecordset=m_pConnection - & gt; Execute (this, & amp; RecordsAffected adCmdText);

while(! M_pRecordset - & gt; ADOEOF)
{
Temprow=m_pRecordset - & gt; TotalCnt GetCollect (" ");
Temprow. ChangeType (VT_I4);
Int uValue=https://bbs.csdn.net/topics/temprow.lVal;
M_pRecordset - & gt; MoveNext ();
}
//m_pRecordset - & gt; Close ();
}
Catch _com_error (e)
{
Cstrings errormessage;
Errormessage. The Format (_T (" insert failed! Please click on the button "enter the database" again. \ r \ n error message: error description: % s % s "), e.E rrorMessage (), (LPCSTR) e.D escription ());
AfxMessageBox (errormessage);
The return;
}

Results the break point to see the results as follows (the value of the uValue)


Where is this is write wrong?

CodePudding user response:

Bool CDBAdo: : GetFieldValue (LPCTSTR lpcsrFieldName, INT& NValue)
{
NValue=https://bbs.csdn.net/topics/0;
Try
{
_variant_t vtFld=m_ptrRecordset - & gt; Fields - & gt; The GetItem (lpcsrFieldName) - & gt; The Value;
The switch (vtFld vt)
{
Case VT_BOOL:
{
NValue=https://bbs.csdn.net/topics/vtFld.boolVal;
break;
}
Case VT_I2:
Case VT_UI1:
{
NValue=https://bbs.csdn.net/topics/vtFld.iVal;
break;
}
Case VT_NULL:
Case VT_EMPTY:
{
NValue=https://bbs.csdn.net/topics/0;
break;
}
Default: nValue=https://bbs.csdn.net/topics/vtFld.iVal;
}
return true;
}
The catch (_com_error & amp; ComError)
{
RecordErrorMsg (comError);
}

return false;
}
Add VT_I4,
 enum VARENUM 
{VT_EMPTY=0,
VT_NULL=1,
VT_I2=2,
VT_I4=3,
VT_R4=4,
VT_R8=5,
VT_CY=6,
VT_DATE=7,
VT_BSTR=8,
VT_DISPATCH=9,
VT_ERROR=10,
VT_BOOL=11,
VT_VARIANT=12,
VT_UNKNOWN=13,
VT_DECIMAL=14,
VT_I1=16,
VT_UI1=17,
VT_UI2=18,
VT_UI4=19,
VT_I8=20,
VT_UI8=21,
VT_INT=22,
VT_UINT=23,
VT_VOID=24,
VT_HRESULT=25,
VT_PTR=26,
VT_SAFEARRAY=27,
VT_CARRAY=28,
VT_USERDEFINED=29,
VT_LPSTR=30,
VT_LPWSTR=31,
VT_RECORD=36,
VT_INT_PTR=37,
VT_UINT_PTR=38,
VT_FILETIME=64,
VT_BLOB=65,
VT_STREAM=66,
VT_STORAGE=67,
VT_STREAMED_OBJECT=68,
VT_STORED_OBJECT=69,
VT_BLOB_OBJECT=70,
VT_CF=71,
VT_CLSID=72,
VT_VERSIONED_STREAM=73,
XFFF VT_BSTR_BLOB=0,
VT_VECTOR=0 x1000,
VT_ARRAY=0 x2000,
X4000 VT_BYREF=0,
VT_RESERVED=0 x8000,
VT_ILLEGAL=0 XFFFF,
XFFF VT_ILLEGALMASKED=0,
VT_TYPEMASK=0 XFFF
};

CodePudding user response:

Your column enumeration type enum VARENUM in WTypes. Has been defined in the h, in my own project to redefine? Then write a function to determine what values returned in each case? What I mean is the result of a SQL query to accurately read out, rather than give a value to it,
Sorry, just contact with this knowledge, don't know what you mean, could you please explain it again? According to the interpretation of the small white, thank you

CodePudding user response:

Execute (this, & amp; RecordsAffected adCmdText);
RecordsAffected equivalent to the SQL in @ @ ROWCOUNT, don't need to be specially select @ @ ROWCOUNT execution

CodePudding user response:

refer to the second floor xhlu response:
you column enumeration type enum VARENUM in WTypes. H has a definition, in my own project to redefine? Then write a function to determine what values returned in each case? What I mean is the result of a SQL query to accurately read out, rather than give a value to it,
Sorry, just contact with this knowledge, don't know what you mean, could you please explain it again? According to the interpretation of the small white, thanks

Not allow you to redefine the meaning, meaning is to compare the above code do not have this type, you can add to read type

CodePudding user response:

reference 4 floor gouyanfen response:
Quote: refer to the second floor xhlu response:

Your column enumeration type enum VARENUM in WTypes. Has been defined in the h, in my own project to redefine? Then write a function to determine what values returned in each case? What I mean is the result of a SQL query to accurately read out, rather than give a value to it,
Sorry, just contact with this knowledge, don't know what you mean, could you please explain it again? According to the interpretation of the small white, thanks

Not allow you to redefine the meaning, meaning is to compare the above code do not have this type, you can add to read type

Thank you, I see, the problem is @ @ ROWCOUNT the return value is wrong, the query in the SQL server returns @ @ ROWCOUNT is right, but in the MFC return values are often wrong (sometimes) correctly, use the following code reading,
 while (! M_pRecordset - & gt; ADOEOF) 
{
The count=m_pRecordset - & gt; GetCollect (" CNT ");
M_pRecordset - & gt; MoveNext ();
}
InsertCnt=_ttoi ((LPCTSTR) (_bstr_t) count);

What reason is this?

CodePudding user response:

The
reference 3 floor ZWFGDLC response:
Execute (this, & amp; RecordsAffected adCmdText);
RecordsAffected equivalent to the SQL in @ @ ROWCOUNT, do not need specially to execute the select @ @ ROWCOUNT

null
  • Related