prabha haran

prabha haran

  • NA
  • 81
  • 32.2k

update two rows with same id in database

Mar 27 2017 3:38 AM
hi
in c# code how to update a database where two rows have same id ,when i update the first row values get updated to both the rows and my code is
 
for (int i = 0; i < SalesInvoiceGridView.Rows.Count; i++)
{
string pcode = SalesInvoiceGridView.Rows[i].Cells[3].Text;
DataSet dp = da.GetDataSet("select ProductId from Tbl_Product where ProductCode ='" + pcode.ToString() + "'");
var Gender = dp.Tables[0].Rows[0][0].ToString();
int prodid = Convert.ToInt32(Gender);
DataSet dp1 = da.GetDataSet("select Barcode from Tbl_Barcodes where Product_Id ='" + prodid + "'");
var bcode = dp1.Tables[0].Rows[0][0].ToString();
DataSet dp2 = da.GetDataSet("select Price from Tbl_Product where ProductId ='" + prodid + "'");
var pric = dp2.Tables[0].Rows[0][0].ToString();
decimal pricp = Convert.ToDecimal(pric);
DataSet dp3 = da.GetDataSet("select UnitId from Tbl_Product where ProductId ='" + prodid + "'");
var uid = dp3.Tables[0].Rows[0][0].ToString();
int u1id = Convert.ToInt16(uid);
DataSet dp4 = da.GetDataSet("select UnitName from Tbl_UOM where UnitId ='" + u1id + "'");
var uname = dp4.Tables[0].Rows[0][0].ToString();
string u1name = uname;


cmd.CommandText = ("Update Tbl_ReceiveStockProducts Set SRId=@SRId, ProductId=@ProductId,Quantity=@Quantity,Amount=@Amount,NetAmount=@NetAmount,DiscountAmt=@DiscountAmt,ItemCode=@ItemCode,UOMId=@UOMId,Barcode=@Barcode,Price=@Price where SRId=" + insertedID + "");
//cmd.Parameters.AddWithValue("@STId", SalesInvoiceGridView.Rows[i].Cells[0].ToString());
cmd.Parameters.AddWithValue("@Quantity", Convert.ToDecimal(SalesInvoiceGridView.Rows[i].Cells[6].Text));
//cmd.Parameters.AddWithValue("@Rights", SalesInvoiceGridView.Rows[i].Cells[2].ToString());
cmd.Parameters.AddWithValue("@Amount", Convert.ToDecimal(SalesInvoiceGridView.Rows[i].Cells[5].Text));
cmd.Parameters.AddWithValue("@NetAmount", Convert.ToDecimal(SalesInvoiceGridView.Rows[i].Cells[7].Text));
cmd.Parameters.AddWithValue("@DiscountAmt", Convert.ToDecimal(SalesInvoiceGridView.Rows[i].Cells[9].Text));
//cmd.Parameters.AddWithValue("@Tax", SalesInvoiceGridView.Rows[i].Cells[6].ToString());
cmd.Parameters.AddWithValue("@ItemCode", SalesInvoiceGridView.Rows[i].Cells[3].Text);
cmd.Parameters.AddWithValue("@UOMId", u1id);
//cmd.Parameters.AddWithValue("@Barcode", SalesInvoiceGridView.Rows[i].Cells[9].ToString());
cmd.Parameters.AddWithValue("@ProductId", prodid);
cmd.Parameters.AddWithValue("@SRId", insertedID);
cmd.Parameters.AddWithValue("@Barcode", bcode);
cmd.Parameters.AddWithValue("@Price", pricp);
con.Open();
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
con.Close();
//SalesInvoiceGridView.EditIndex = -1;




Answers (3)