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: