Two immediate problems:
i) You check row by row and if that particular row doesn't match, you add a new row.
ii) The adding a new row happens inside the iteration of the row collection - very bad move!
Possible solution
var found = false;
foreach (DataGridViewRow row1 in dgvmaingrid.Rows)
{
if (row1.Cells["PNAME"].Value.Equals(txtProdsearch.Text.Trim()) &&
row1.Cells["DESC"].Value.Equals(txtDesc.Text.Trim()))
{
row1.Cells["QTY1"].Value = (double.Parse(row1.Cells["QTY1"].Value.ToString()) +
double.Parse(txtQty.Text));
row1.Cells["NETAMT"].Value = Convert.ToDecimal(String.Format("{0:0.00}",
Convert.ToDecimal((double.Parse(row1.Cells["NETAMT"].Value.ToString()) +
double.Parse(txtNetPrice.Text))))).ToString();
found = true;
break;
}
}
if (!found)
{
}