protected void btn_delete_Click(object sender, EventArgs e) { try { con = DBaccess.GetConnection(); string getperiodstr = ""; getperiodstr = "select * from( Select procagent,Agent_Name from (sELECT Agent_id as procagent FROM Procurementimport where Plant_Code='" + plant_Code + "' and Prdate between '" + txt_FromDate.Text + "' and '" + txt_ToDate.Text + "' GROUP BY Agent_id ) as procimport left join(Select agent_id,Agent_Name from Agent_Master where Plant_code=" + plant_Code + ") as am on procimport.procagent=am.Agent_Id ) as gg where gg.procagent=Agent_Name"; SqlCommand cmdperiod = new SqlCommand(getperiodstr, con); SqlDataAdapter sall = new SqlDataAdapter(cmdperiod); getmissagent.Rows.Clear(); sall.Fill(getmissagent); if (getmissagent.Rows.Count > 0) { GridView2.DataSource = getmissagent; GridView2.DataBind(); GridView2.Visible = true; } else { GridView2.Visible = false; //Check remmarks Update or Not int Rstatus = 0; Rstatus = Bllusers.Remarksstatus(Company_code, plant_Code, txt_FromDate.Text, txt_ToDate.Text); if (Rstatus >= 1) { string remarksmsg = "Check the RemarksUpdate..."; uscMsgBox1.AddMessage(remarksmsg, MessageBoxUsc_Message.enmMessageType.Success); } else { //Check the Data Already Transfer or Not int DataTrasfer = 0; DataTrasfer = Bllusers.DatatransferCheck(Company_code, plant_Code, txt_FromDate.Text, txt_ToDate.Text); if (DataTrasfer >= 1) { string remarksmsg = "Already DataTransfer..."; uscMsgBox1.AddMessage(remarksmsg, MessageBoxUsc_Message.enmMessageType.Success); } else { try { using (con = DBaccess.GetConnection()) { setBO(); SqlCommand cmdd = new SqlCommand("DELETE from PROCUREMENT where plant_code='" + plant_Code + "' and prdate between '" + txt_FromDate.Text + "' and '" + txt_ToDate.Text + "' ", con); cmdd.ExecuteNonQuery(); impdbBL.deleteimport(rateBO); SqlCommand cmd = new SqlCommand(); SqlCommand cmd1 = new SqlCommand(); DataTable dtt = new DataTable(); SqlDataAdapter daa; daa = new SqlDataAdapter("SELECT * from PROCUREMENTIMPORT where plant_code='" + plant_Code + "' and prdate between '" + txt_FromDate.Text + "' and '" + txt_ToDate.Text + "' ", con); daa.Fill(dtt); int count1 = dtt.Rows.Count; DataTable dt = new DataTable(); SqlDataAdapter da; da = new SqlDataAdapter("SELECT * from PROCUREMENT where plant_code='" + plant_Code + "' and prdate between '" + txt_FromDate.Text + "' and '" + txt_ToDate.Text + "' ", con); da.Fill(dt); int count = dt.Rows.Count; cmd.Connection = con; cmd1.Connection = con; if (count == count1) { con.Close(); string countmsg = count.ToString() + "__Rows are inserted..."; uscMsgBox1.AddMessage(countmsg, MessageBoxUsc_Message.enmMessageType.Success); } else { SqlCommand cmd2 = new SqlCommand("DELETE from PROCUREMENT where plant_code='" + plant_Code + "' and prdate between '" + txt_FromDate.Text + "' and '" + txt_ToDate.Text + "' ", con); cmd2.ExecuteNonQuery(); con.Close(); string countmsg = "Datas Not Inserted..."; uscMsgBox1.AddMessage(countmsg, MessageBoxUsc_Message.enmMessageType.Success); } } } catch (Exception ex) { con.Close(); using (con = DBaccess.GetConnection()) { SqlCommand cmd = new SqlCommand(); SqlCommand cmd1 = new SqlCommand(); DataTable dtt = new DataTable(); SqlDataAdapter daa; daa = new SqlDataAdapter("SELECT * from PROCUREMENTIMPORT where plant_code='" + plant_Code + "' and prdate between '" + txt_FromDate.Text + "' and '" + txt_ToDate.Text + "' ", con); daa.Fill(dtt); int count1 = dtt.Rows.Count; DataTable dt = new DataTable(); SqlDataAdapter da; da = new SqlDataAdapter("SELECT * from PROCUREMENT where plant_code='" + plant_Code + "' and prdate between '" + txt_FromDate.Text + "' and '" + txt_ToDate.Text + "' ", con); da.Fill(dt); int count = dt.Rows.Count; cmd.Connection = con; cmd1.Connection = con; if (count == count1) { con.Close(); string countmsg = count.ToString() + "__Rows are inserted..."; uscMsgBox1.AddMessage(countmsg, MessageBoxUsc_Message.enmMessageType.Success); } else { SqlCommand cmd2 = new SqlCommand("DELETE from PROCUREMENT where plant_code='" + plant_Code + "' and prdate between '" + txt_FromDate.Text + "' and '" + txt_ToDate.Text + "' ", con); cmd2.ExecuteNonQuery(); con.Close(); string countmsg = "Datas Not Inserted..."; uscMsgBox1.AddMessage(countmsg, MessageBoxUsc_Message.enmMessageType.Success); } } } } } } } catch (Exception EX) { } }