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:ata::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:ata;
using namespace System:ata::SqlClient;
#include <cstring>
#include <iostream>
using namespace std;
// This is the entry point for this application.
int _tmain(void)
{
try{
SqlConnection *myCon = new SqlConnection("Data Source=TITAN;User ID=testuser;Password=testpassword;initial catalog=Demo;"
myCon->Open();
SqlCommand *myCmd = new SqlCommand("_Update_Unit_Ship_Weight", myCon);
myCmd->CommandType = CommandType::StoredProcedure;
SqlParameter* retParam=myCmd->Parameters->Add("RetVal",SqlDbType::Int,4);
retParam->Direction=ParameterDirection::ReturnValue;
char test[6] = "40021";
myCmd->Parameters->Add("@order_number",SqlDbType::VarChar,5);
//*******Next line gives the error during build
myCmd->Parameters->Item[1]->Value = test;
int cnt;
cnt=myCmd->ExecuteNonQuery();
Console::WriteLine("Number of rows affected:{0}; Return Value:{1}",
cnt.ToString(),retParam->Value);
myCon->Close();
}
catch(SqlException *mySqlEx)
{
for(int i=0;i<mySqlEx->Errors->Count;i++)
{
Console::WriteLine("Source={0};Message={1};",mySqlEx->Errors->
Item->Source,mySqlEx->Errors->Item->Message);
}
}
catch(System::Exception *ex)
{
Console::WriteLine(ex->get_Message());
}
}
However when I change the code to use a variable to supply the parameter, I get this error:
error C2664:'System:ata::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:ata;
using namespace System:ata::SqlClient;
#include <cstring>
#include <iostream>
using namespace std;
// This is the entry point for this application.
int _tmain(void)
{
try{
SqlConnection *myCon = new SqlConnection("Data Source=TITAN;User ID=testuser;Password=testpassword;initial catalog=Demo;"
myCon->Open();
SqlCommand *myCmd = new SqlCommand("_Update_Unit_Ship_Weight", myCon);
myCmd->CommandType = CommandType::StoredProcedure;
SqlParameter* retParam=myCmd->Parameters->Add("RetVal",SqlDbType::Int,4);
retParam->Direction=ParameterDirection::ReturnValue;
char test[6] = "40021";
myCmd->Parameters->Add("@order_number",SqlDbType::VarChar,5);
//*******Next line gives the error during build
myCmd->Parameters->Item[1]->Value = test;
int cnt;
cnt=myCmd->ExecuteNonQuery();
Console::WriteLine("Number of rows affected:{0}; Return Value:{1}",
cnt.ToString(),retParam->Value);
myCon->Close();
}
catch(SqlException *mySqlEx)
{
for(int i=0;i<mySqlEx->Errors->Count;i++)
{
Console::WriteLine("Source={0};Message={1};",mySqlEx->Errors->
Item->Source,mySqlEx->Errors->Item->Message);
}
}
catch(System::Exception *ex)
{
Console::WriteLine(ex->get_Message());
}
}