Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing SQL stored procedure in VC++; Object__gc error

Status
Not open for further replies.

stroyer74

IS-IT--Management
Jan 22, 2003
70
US
I'm working with VC++.NET and basing my test code off Microsoft Q310071 article. I have been able to successfully use their sample code for executing a stored procedure and pass parameters to it.

However when I change the code to use a variable to supply the parameter, I get this error:

error C2664:'System::Data::SqlClient::SqlParameter::set_Value': cannot convert parameter 1 from 'char[6]' to 'System::Object__gc*'

Anyone have any suggestions?

Thanks
Sheldon

****code

//Program example taken from Microsoft Q310071 article
//Using the SQL Client rather than the OLE DB Data Provider

#include "stdafx.h"
#using <mscorlib.dll>
#include <tchar.h>
#using <system.dll>
using namespace System;
#using <system.data.dll>
using namespace System::Data;
using namespace System::Data::SqlClient;
#include <cstring>
#include <iostream>
using namespace std;

// This is the entry point for this application.
int _tmain(void)
{
try{
SqlConnection *myCon = new SqlConnection(&quot;Data Source=TITAN;User ID=testuser;Password=testpassword;initial catalog=Demo;&quot;);
myCon->Open();

SqlCommand *myCmd = new SqlCommand(&quot;_Update_Unit_Ship_Weight&quot;, myCon);
myCmd->CommandType = CommandType::StoredProcedure;

SqlParameter* retParam=myCmd->Parameters->Add(&quot;RetVal&quot;,SqlDbType::Int,4);
retParam->Direction=ParameterDirection::ReturnValue;

char test[6] = &quot;40021&quot;;

myCmd->Parameters->Add(&quot;@order_number&quot;,SqlDbType::VarChar,5);
//*******Next line gives the error during build
myCmd->Parameters->Item[1]->Value = test;

int cnt;

cnt=myCmd->ExecuteNonQuery();
Console::WriteLine(&quot;Number of rows affected:{0}; Return Value:{1}&quot;,
cnt.ToString(),retParam->Value);

myCon->Close();

}
catch(SqlException *mySqlEx)
{
for(int i=0;i<mySqlEx->Errors->Count;i++)
{
Console::WriteLine(&quot;Source={0};Message={1};&quot;,mySqlEx->Errors->
Item->Source,mySqlEx->Errors->Item->Message);
}
}
catch(System::Exception *ex)
{
Console::WriteLine(ex->get_Message());
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top