hey guys, im trying different ways of deleting from a gridview
So i have used the autogenerate functions on the data source and the gridview,
now this is the error im getting:
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'int'.
an this is the stack trace:
[SqlException (0x80131904): Incorrect syntax near
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +2073550
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5064508
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +215
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +987
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +178
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +137
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +394
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDelete(IDictionary keys, IDictionary oldValues) +576
System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) +92
System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +946
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +1161
System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +210
System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +176
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
OK. so where it says incorrect syntax near int i cannot see an error with the delete command this is the string i am using:
DeleteCommand="DELETE FROM Customer WHERE ([Customer ID] = @ID)">
i keep getting the error and its very frustrating, i have even tried removing the [] and the space near = and still no joy.
the other problem i have is as this was not working i thought i would hardcode some button and text box to do the same function but it is not deleting either.
this is the code i have used for delete button:
protected void deleteButton1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TravelShopConnectionString1"].ConnectionString);
SqlCommand deleteUser = new SqlCommand("DELETE FROM Customer WHERE [Customer ID] = @ID", conn);
deleteUser.CommandType = CommandType.Text;
try
{
conn.Open();
deleteUser.ExecuteNonQuery();
Response.Redirect("AdminRegistered.aspx");
}
catch (Exception)
{
Response.Write("ERROR delete failed");
}
}
any help would be greatly appreciated
Regards Matt.