I got this 'incorrect syntax near spoc (stored procedure)' error from the following:
string connectionString = getConnectionString("ConnectionString");
SqlConnection conn = new SqlConnection(connectionString);
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("sproc_aspnet_StocksInLists_RemoveStocksFromList", conn);
try
{
conn.Open();
command.Parameters.AddWithValue("@ListId", ddlList.SelectedValue);
iRes = command.ExecuteNonQuery();
if (iRes < 0) throw new Exception("Error removing stocks from list");
}
The bug fix is to set the command type:
string connectionString = getConnectionString("ConnectionString");
SqlConnection conn = new SqlConnection(connectionString);
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("sproc_aspnet_StocksInLists_RemoveStocksFromList", conn);
command.CommandType = System.Data.CommandType.StoredProcedure;
try
{
conn.Open();
command.Parameters.AddWithValue("@ListId", ddlList.SelectedValue);
iRes = command.ExecuteNonQuery();
if (iRes < 0) throw new Exception("Error removing stocks from list");
}
No comments:
Post a Comment