Delete confirm in asp:GridView

Aug 11 2006 3:36 PM

Hi,

I have a gridview which takes it's values from an sqldatassource.I have an extra column in gridview which contains a linkbutton for each row( delete button) and when the user clicks on the button a pop up fires for delete confirmation, i click ok and i see this error message
"Must declare the scalar variable "@id_polis".  and
"Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable "@id_polis".

Source Error:

Line 52:     connection.Open();
Line 53:     SqlCommand Command = new SqlCommand("DELETE FROM ?????S WHERE [id_polis] = @id_polis ", connection);
Line 54:     Command.ExecuteNonQuery();
Line 55:     Command.Connection.Close();
Line 56:     GridView1.DataBind();

.
Here is what i have done so far :

(button code) :

<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete" Text="DELETE" OnClientClick='<%# Eval("id_polis","return confirm(\"Delete the datasource {0}?\");") %>'></asp:LinkButton>

(delete code)

protected
void SqlDataSource1_Deleted(object sender, EventArgs e)

{

SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

connection.Open();

SqlCommand Command = new SqlCommand("DELETE FROM ??„?‘ WHERE [id_polis] = @id_polis ", connection);

Command.ExecuteNonQuery();

Command.Connection.Close();

GridView1.DataBind();

}

 

what can i do?????????

Thanks....





Answers (1)