I am getting following error, while passing a C++ string variable to SQL insert command:
error C2679: binary '+' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
Below is the code:
int main()
{
int empid = 12;
int phone = 23456;
std::string fname = "Pavan";
SqlDataAdapter^ custDA = gcnew SqlDataAdapter("SELECT Emp_ID,FirstName,LastName,Phone,Service FROM Employee",
"Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Employee");
SqlConnection^ custConn = custDA->SelectCommand->Connection;
//custDA->MissingSchemaAction = MissingSchemaAction::AddWithKey;
try
{
custConn->Open();
custDA->InsertCommand = gcnew SqlCommand("insert into Employee (Emp_ID,FirstName,LastName,Phone,Service) values("+empid_+",'"+fname+"','Gupta',"+phone_+",'gdjdjsjsaa')",custConn);
custDA->InsertCommand->ExecuteNonQuery();
printf("Row(s) Inserted !! ");
}
catch (Exception^ ex)
{
printf("%s",ex->ToString());
}
custConn->Close();
}