0

Hello .
I have Gridview which display a table that contain a Foreign Key , and because of
Foreign Key , The Automatic Generate Delete Link Can't be work correctly , because SqlQuery not one Table ,...

So i must Type a code in Row Delete Event ,
if my thought is False ,... please anyone Tell me the Right understand .

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string id = e.RowIndex.ToString();
        SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlCommand cmd=new SqlCommand("DELETE FROM Orders WHERE id = @id",con);
        cmd.Parameters.Add("@id",SqlDbType.Int);
        cmd.Parameters["@id"].Value=Convert.ToInt32(id);
        try
        {
            con.Open();
            cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            Response.Write(ex);
        }
        finally
        {
            con.Close();
        }
    }

ok , The problem is Sometimes that link (delete) Work , Sometimes not work ,
i expect the problem is about id .
So ,Please anyone Tell me what can i do ,...

Thank,...
Sorry For my Bad English :( :twisted:

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by croker10
0

Can you post your gridview markup as well? That would help to see what you are doing and what may be causing the problems.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.