How to receive data from SQL database by ODBC class

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 1
Reputation: alanliao09 is an unknown quantity at this point 
Solved Threads: 0
alanliao09 alanliao09 is offline Offline
Newbie Poster

How to receive data from SQL database by ODBC class

 
0
  #1
Sep 3rd, 2008
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:
  1. try{
  2. myCon->Open();
  3. OdbcCommand^ myCmd = gcnew OdbcCommand(MySP,myCon); //MySp is my store procedure and myCon is the SQL server connection string
  4. myCmd->Parameters->Add("xml",OdbcType::Char,200);
  5. myCmd->Parameters->default[0]->Direction=ParameterDirection::ReturnValue;
  6. OdbcDataReader^ myReader = myCmd->ExecuteReader(); //Execute the sending
  7.  
  8. while (myReader->Read())
  9. {
  10. Console::WriteLine();
  11. for(Int32 i=0;i<myReader->FieldCount;i++)
  12. {
  13. Console::WriteLine("{0}:{1}",(myReader->GetName(i))->ToString(),(myReader->GetValue(i))->ToString());
  14. }
  15. }
  16. myReader->Close();
  17. Console::WriteLine("OutputParamVal={0};ReturnVal={1}",myCmd->Parameters->default[0]->Value,myCmd->Parameters->default[1]->Value);
  18. }
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
Last edited by cscgal; Sep 3rd, 2008 at 7:14 pm. Reason: Added code tags
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC