getting error "There is already an open DataReader associated with this Command which must be closed first.The connection was not closed. The connection's current state is open."
Please any one can help me to solve the error.
here is my code
- double totalExchange=0, totalBuyBack=0;
- double markup=0;
- void getData()
- {
- if (txtLotNumber.Text != "")
- {
- string total = "";
- try
- {
- string com = "select * from PriceBreakupSaleBuyBack where itemNumber=@itemNumber;";
- com += "select G_From, G_To, value from MarkupSlab where GorP='G'";
- using (SqlCommand cmd = new SqlCommand(com, con))
- {
- cmd.Parameters.AddWithValue("@itemNumber", txtLotNumber.Text);
- con.Open();
- using (SqlDataReader dr = cmd.ExecuteReader())
- {
- while (dr.Read())
- {
- lblLotNumber.Text = dr["itemNumber"].ToString();
- lblDescription.Text = dr["DesignDescription"].ToString();
- lblGrossWt.Text = dr["GrossWeight"].ToString();
- lblDesign.Text = dr["design"].ToString();
- lblDiamondWt.Text = dr["DiamondWeight"].ToString();
- lblGoldWt.Text = dr["GoldWeight"].ToString();
- total = dr["itemDescription"].ToString();
- if (total == "Total")
- {
- totalBuyBack += Convert.ToDouble(dr["Amount"].ToString());
- totalExchange += Convert.ToDouble(dr["excAmount"].ToString());
- }
- }
- double diaWt = Convert.ToDouble(lblDiamondWt.Text);
- if (diaWt > 0.25)
- {
- lblTotalBuyBk.Text = "" + totalBuyBack;
- lblTotalEx.Text = "" + totalExchange;
- fillGrid();
- note();
- }
- else
- {
- if (dr.NextResult())
- {
- while (dr.Read())
- {
- double Gfr = Convert.ToDouble(dr["G_From"].ToString());
- double Gto = Convert.ToDouble(dr["G_To"].ToString());
- if (totalExchange >= Gfr && totalExchange <= Gto)
- {
- markup = Convert.ToDouble(dr["value"].ToString());
- }
- }
- }
- con.Close();
- totalExchange *= 1.25;
- totalBuyBack *= 1.25;
- totalExchange += totalExchange * markup / 100;
- totalBuyBack += totalBuyBack * markup / 100;
- lblTotalBuyBk.Text = "" + totalBuyBack;
- lblTotalEx.Text = "" + totalExchange;
- note();
- }
- }
- }
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- else
- {
- Response.Write("");
- }
- }
- void fillGrid()
- {
- try
- {
- string com = "select itemGroup, Item, ItemDescription, Pieces, Weight, ExcAmount, Amount from PriceBreakupSaleBuyBack";
- SqlCommand cmd = new SqlCommand(com, con);
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- DataSet ds = new DataSet();
- da.Fill(ds);
- GridView1.DataSource = ds;
- GridView1.DataBind();
- string data;
- for (int i = 0; i < (GridView1.Rows.Count); i++)
- {
- data=GridView1.Rows[i].Cells[0].Text.ToString();
- data = data.Split(' ').First();
- GridView1.Rows[i].Cells[0].Text = data;
- }
- if (GridView1.Rows.Count > 0)
- {
- GridView1.HeaderRow.Cells[0].Text = "Type";
- GridView1.HeaderRow.Cells[3].Text = "Pcs/KT";
- GridView1.HeaderRow.Cells[4].Text = "Wt";
- }
- color();
- }
- catch (Exception ex) { Response.Write(ex.Message); }
- }
- void color()
- {
- string data;
- for (int i = 0; i < (GridView1.Rows.Count); i++)
- {
- data = GridView1.Rows[i].Cells[2].Text.ToString();
- if (data.Equals("Total"))
- {
- GridView1.Rows[i].ForeColor = Color.Red;
- }
- }
- }
- void note()
- {
- string note="";
- string com = "select * from PriceBreakupBuyBackNotes";
- SqlCommand cmd = new SqlCommand(com, con);
- con.Open();
- SqlDataReader dr;
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- note += dr["id"].ToString()+". ";
- note += dr["note"].ToString()+"
"; - }
- lblNote.Text = note;
- lblNote.ForeColor = Color.Red;
- con.Close();
- }

Amit GuptaPosted Dec 21, 2017, 12:48 AM
Altaf AnsariPosted Dec 20, 2017, 11:53 PM
";
Sk JhaPosted Dec 20, 2017, 11:36 PM
Altaf AnsariPosted Dec 20, 2017, 11:15 PM
";
Sk JhaPosted Dec 20, 2017, 11:10 PM