| | |
How to receive data from SQL database by ODBC class
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2008
Posts: 1
Reputation:
Solved Threads: 0
I am currently using the ODBC class for c++ to connect and query a SQL database. I am calling a stored procedure within the database like so:
The stored procedure will perform a series of operations on several of the tables within the database. Depending on the data it will sometimes return data in a table format back to my program. At other times it will not. My question is, how do I receive this data when the stored procedure sends it back to my program. I know I am correctly calling the stored procedure as the database shifts around the data within the tables during the times it does not send anything back to my program. My colleague has been able to receive the data returns when calling the same stored procedure, however he is using Visual Basic.
Additional info:
The stored procedure does not accept parameters.
If anyone has any suggestions with how to receive returned data from a stored procedure, I would greatly appreciate your help. If the ODBC class is unable to do what I am requesting, I would be happy to use something else as well.
Thanks
C++ Syntax (Toggle Plain Text)
try{ myCon->Open(); OdbcCommand^ myCmd = gcnew OdbcCommand(MySP,myCon); //MySp is my store procedure and myCon is the SQL server connection string myCmd->Parameters->Add("xml",OdbcType::Char,200); myCmd->Parameters->default[0]->Direction=ParameterDirection::ReturnValue; OdbcDataReader^ myReader = myCmd->ExecuteReader(); //Execute the sending while (myReader->Read()) { Console::WriteLine(); for(Int32 i=0;i<myReader->FieldCount;i++) { Console::WriteLine("{0}:{1}",(myReader->GetName(i))->ToString(),(myReader->GetValue(i))->ToString()); } } myReader->Close(); Console::WriteLine("OutputParamVal={0};ReturnVal={1}",myCmd->Parameters->default[0]->Value,myCmd->Parameters->default[1]->Value); }
Additional info:
The stored procedure does not accept parameters.
If anyone has any suggestions with how to receive returned data from a stored procedure, I would greatly appreciate your help. If the ODBC class is unable to do what I am requesting, I would be happy to use something else as well.
Thanks
Last edited by cscgal; Sep 3rd, 2008 at 7:14 pm. Reason: Added code tags
![]() |
Other Threads in the C++ Forum
- Previous Thread: Frustration with Windows API
- Next Thread: I can't get this to work, send keystroke too notepad
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





