Data base field type stored in two times
using (SqlConnection connect = new SqlConnection(db.Connectionstring())){
using (SqlCommand command = new SqlCommand())
{
string pro = "";
int qty;
int totqty;
int i=0;
foreach (DataGridViewRow rows in dataGridView1.Rows)
{
SqlConnection con1 = new SqlConnection(db.Connectionstring());
con1.Open();
SqlCommand cmd1 = new SqlCommand("select * from sales where empnames='" + comboBox1.Text + "' ", con1);
SqlDataReader dr = cmd1.ExecuteReader();
if (dr.HasRows)
{
//while (dr.Read())
//{
SqlConnection con2 = new SqlConnection(db.Connectionstring());
con2.Open();
SqlCommand cmd2 = new SqlCommand("update sales set empnames=@empnames+'" + comboBox1.Text + "', categories=@categories, weight=@weight,per=@per,wastage=@wastage,customer=@customer,party=@party where date=@date ", con2);
cmd2.Parameters.AddWithValue("@empnames", Convert.ToString((comboBox1.Text)));
cmd2.Parameters.AddWithValue("@date", Convert.ToDouble(rows.Cells[0].Value));
cmd2.Parameters.AddWithValue("@categories", Convert.ToString(rows.Cells[1].Value));
cmd2.Parameters.AddWithValue("@weight", Convert.ToString((rows.Cells[2].Value)));
cmd2.Parameters.AddWithValue("@per", Convert.ToDouble(rows.Cells[3].Value));
cmd2.Parameters.AddWithValue("@wastage", Convert.ToString((rows.Cells[4].Value)));
cmd2.Parameters.AddWithValue("@customer", Convert.ToDouble(rows.Cells[5].Value));
cmd2.Parameters.AddWithValue("@party", Convert.ToString((rows.Cells[6].Value)));
cmd2.ExecuteNonQuery();
con2.Close();
SqlConnection con4 = new SqlConnection(db.Connectionstring());
con4.Open();
SqlCommand cmd4 = new SqlCommand("update sales set amtcst='" + txt_netamount.Text + "', amtparty='" + txtparty.Text + "', amtfinal='" + txtfinal.Text + "' where empnames='" + comboBox1.SelectedText + "'", con4);
cmd4.ExecuteNonQuery();
con4.Close();
// }
}
else
{
SqlConnection con3 = new SqlConnection(db.Connectionstring());
con3.Open();
SqlCommand cmd3 = new SqlCommand("insert into sales(empnames,date,categories,weight,per,wastage,customer,party,amtcst,amtparty,amtfinal)values('" + comboBox1.Text + "', '" + rows.Cells[0].Value + "','" + rows.Cells[1].Value + "','" + rows.Cells[2].Value + "','" + rows.Cells[3].Value + "','" + rows.Cells[4].Value + "','" + rows.Cells[5].Value + "','" + rows.Cells[6].Value + "','" + txt_netamount.Text + "','" + txtparty.Text + "','" + txtfinal.Text + "')", con3);
cmd3.ExecuteNonQuery();
con3.Close();
}
}
}
}