Hi Mubarak,
You can move code into stored procedure and then you can execute stored procedure and this will be much faster.
2dn you can try with below logic.
if (str == "sale")
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (ds.Tables[0].Rows[i]["Sr_No"] != null)
{
cmd.Parameters.AddWithValue("@Item", ds.Tables[0].Rows[i]["Sr_No"]);
cmd.Parameters.AddWithValue("@SalePart", ds.Tables[0].Rows[i]["Sale_Part_No"]);
cmd.Parameters.AddWithValue("@Sale_Price", ds.Tables[0].Rows[i]["Sale_Price"]);
cmd.Parameters.AddWithValue("@Partname", ds.Tables[0].Rows[i]["Sale_Part_Desc"]);
cmd.Parameters.AddWithValue("@LocalPartNo", ds.Tables[0].Rows[i]["Local_Part_No"]);
cmd.Parameters.AddWithValue("@Parent_Part_No ", ds.Tables[0].Rows[i]["Parent_Part_No"]);
cmd.Parameters.AddWithValue("@Part_Type_TR_ENG", ds.Tables[0].Rows[i]["Part_Type_TR_ENG"]);
cmd.Parameters.AddWithValue("@Id1", ds.Tables[0].Rows[i]["Sale_Part_No"]);
cmd.Parameters.AddWithValue("@Id2", ds.Tables[0].Rows[i]["Local_Part_No"]);
string query = @"If Not Exists(select * from SalesUpdate where [Item#]=@Item)Begin insert into SalesUpdate ([Item#],[SalePart],[Sale_Price] ,[Part name] ,[LocalPartNo],[Parent_Part_No],[Part_Type_TR_ENG])VALUES(@Item,@SalePart,@Sale_Price,@Partname,@LocalPartNo,@Parent_Part_No,@Part_Type_TR_ENG);End";
cmd = new SqlCommand(query,con);
cmd.ExecuteNonQuery();
cmd = new SqlCommand("select * from SalesUpdate CROSS JOIN specific_page where SalesUpdate.[SalePart]=specific_page.[sale_part#] and SalesUpdate.LocalPartNo=specific_page.[local_part#] and SalesUpdate.[Sale_Price]!=specific_page.[sale_price];", con);
if (cmd.ExecuteScalar() != null)
{
cmd = new SqlCommand("UPDATE specific_page SET [sale_price] =@Sale_Price FROM SalesUpdate WHERE sale_part#=@Id1 and local_part#=@Id2 and specific_page.[sale_price]!= SalesUpdate.[Sale_Price];", con);
cmd.ExecuteNonQuery();
}
}
}
MessageBox.Show("Successfully added.");
}
Hope this help you.