TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sk Jha
NA
113
43.3k
getting connection error when i am calling function inside
Dec 20 2017 11:06 PM
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(
"<!-- Inject Script Filtered -->"
);
}
}
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();
}
Reply
Answers (
5
)
please resolve my query
Compilation error, metadata file '.dll' could not be found