G
Guest
I am a newby with .Net. I tried the following snippet from David Sceppa’s
MS ADO.NET Core Reference book. I get the following error from the SQL
Server Exception:
"System.Datat.SqlClient.SqlExeception:Line 1:Incorrect syntax near “OrderIdâ€.
Line 1: Incorrect syntax near “?â€.
At System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior ……"
I converted the code snippet from the book from C# to C++. It appears to
not like the “?†placeholders. Does anyone have any insight into this error?
Is it supported in C++?
static System:ata::SqlClient::SqlCommand * CreateInsertCommand()
{
String * strSql;
strSql = S"INSERT INTO [tdforderdetails]"
S" (OrderId, ProductID, Quantity, UnitPrice, Discount)"
S" VALUES( ?, ?, ?, ?, ?)";
SqlCommand * cmd = new SqlCommand(strSql,cn); // cn already established
SqlParameterCollection * pc = cmd->Parameters;
pc->Add(S"OrderId", SqlDbType::Int)->Value = __box(11077);
pc->Add(S"ProductID", SqlDbType::Int)->Value = __box(11);
pc->Add(S"Quantity", SqlDbType::SmallInt)->Value = __box(33);
pc->Add(S"UnitPrice", SqlDbType::Money)->Value = __box(14);
pc->Add(S"Discount", SqlDbType::Money)->Value = __box(1.2);
try
{
cmd->ExecuteNonQuery();
}
catch (System:ata::SqlClient::SqlException *e)
{
MessageBox::Show(e->ToString());
}
return cmd;
}
MS ADO.NET Core Reference book. I get the following error from the SQL
Server Exception:
"System.Datat.SqlClient.SqlExeception:Line 1:Incorrect syntax near “OrderIdâ€.
Line 1: Incorrect syntax near “?â€.
At System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior ……"
I converted the code snippet from the book from C# to C++. It appears to
not like the “?†placeholders. Does anyone have any insight into this error?
Is it supported in C++?
static System:ata::SqlClient::SqlCommand * CreateInsertCommand()
{
String * strSql;
strSql = S"INSERT INTO [tdforderdetails]"
S" (OrderId, ProductID, Quantity, UnitPrice, Discount)"
S" VALUES( ?, ?, ?, ?, ?)";
SqlCommand * cmd = new SqlCommand(strSql,cn); // cn already established
SqlParameterCollection * pc = cmd->Parameters;
pc->Add(S"OrderId", SqlDbType::Int)->Value = __box(11077);
pc->Add(S"ProductID", SqlDbType::Int)->Value = __box(11);
pc->Add(S"Quantity", SqlDbType::SmallInt)->Value = __box(33);
pc->Add(S"UnitPrice", SqlDbType::Money)->Value = __box(14);
pc->Add(S"Discount", SqlDbType::Money)->Value = __box(1.2);
try
{
cmd->ExecuteNonQuery();
}
catch (System:ata::SqlClient::SqlException *e)
{
MessageBox::Show(e->ToString());
}
return cmd;
}