Hi,
I am developing windows applications.it shows the following error?
Error:
The DELETE statement conflicted with the REFERENCE constraint "FK_tbl_Report1_tbl_Report2". The conflict occurred in database "Sudheeptest", table "dbo.tbl_Report1", column 'InvoiceNo'.
The statement has been terminated.
Here is my code for delete.how can i delete the row from gridview please give me suggesstions in my code.please do the needful.
private void btn_delete_Click_1(object sender, EventArgs e)
{
if (txt_customeraddress .Text == "" || txt_invoicedate.Text == "")
{
MessageBox.Show("Please Select Record From Grid", "Image Impact Services(IIS)", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=Sudheeptest;integrated security=true");
SqlCommand cmd = new SqlCommand("delete from tbl_report2 where invoiceno=" + invoiceno + "", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
con.Open();
DataTable dt = new DataTable();
da.Fill(dt);
cmd.ExecuteNonQuery();
con.Close();
GridView1.DataSource = dt;
SqlConnection conn = new SqlConnection("data source=mars-104;initial catalog=Sudheeptest;integrated security=true");
SqlCommand cmd1 = new SqlCommand("delete from tbl_report1 where invoiceno=" + invoiceno + "", conn);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
conn.Open();
DataTable dt1 = new DataTable();
da1.Fill(dt1);
cmd1.ExecuteNonQuery();
con.Close();
GridView1.DataSource = dt1;
griddisplay();
MessageBox.Show("Record Delete Successfully","Image Impact Services(IIS)",MessageBoxButtons .OK ,MessageBoxIcon.Information );
}
}
Best,
Sudheep.