C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Assemblies
.NET Core
.NET Standard
Active Directory
ADO.NET
Agile Development
AJAX
Alexa Skills
Algorithms in C#
Android
Angular
Architecture
ArcObject
Artificial Intelligence
ASP.NET
ASP.NET Core
Augmented Reality
Aurelia
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blockchain
Bootstrap
Bot Framework
Business
C#
C# Corner
C, C++, MFC
Career Advice
Chapters
CIO
Cloud
COBOL.NET
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Cortana Development
Cryptocurrency
Cryptography
Crystal Reports
Current Affairs
Custom Controls
Cyber Security
Data Mining
Databases & DBA
Design Patterns & Practices
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
Expression Studio
F#
Files, Directory, IO
Games Programming
GDI+
General
Google Cloud
Google Development
Graphics Design
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Internet & Web
Internet of Things
Ionic
iOS
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
kotlin
Leadership
Learn .NET
LightSwitch
LINQ
Machine Learning
Microsoft 365
Microsoft Office
Microsoft Phone
Mobile Development
Multithreading
NetBeans
Networking
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Power BI
Printing in C#
Products
Progressive Web Apps
Project Management
Python
Q#
QlikView
R
React
Reports using C#
Robotics & Hardware
Ruby on Rails
Salesforce
Security
Servers
SharePoint
SignalR
Silverlight
Smart Devices
Software Testing
SQL Language
SQL Server
Startups
String in C#
Swift
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
WCF
Wearables
Web Development
Web Services
Web3
Windows 10
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML Standard
XML
XNA
XSharp
Register
Login
5
Answers
getting connection error when i am calling function inside
Sk Jha
7y
142
1
Reply
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();
}
Rich Text Editor, TextBoxComment
Editor toolbars
Editing
Undo
Keyboard shortcut Ctrl+Z
Redo
Keyboard shortcut Ctrl+Y
Remove Format
Clipboard/Undo
Cut
Keyboard shortcut Ctrl+X
Copy
Keyboard shortcut Ctrl+C
Tools
Maximize
Styles
Format
Format
Paragraph
Insert/Remove Numbered List
Insert/Remove Bulleted List
Decrease Indent
Increase Indent
Block Quote
Basic Styles
Bold
Keyboard shortcut Ctrl+B
Italic
Keyboard shortcut Ctrl+I
Links
Link
Keyboard shortcut Ctrl+K
Unlink
Insert
Image
Insert Code Snippet
Table
Document
Source
Press ALT 0 for help
◢
Elements path
Post
Reset
Cancel
Answers (
5
)
1
Prasham Sabadra
NA
17.6k
1.2m
8y
Hi Venkat,
Please try this
<script src=”/_layouts/SP.js” type=”text/ecmascript”></script>
Accepted
1
Ramesh Palaniappan
NA
13.2k
722.6k
8y
Please add this line to call your function
ExecuteOrDelayUntilScriptLoaded(myjsfucntion,
"sp.js"
);
Next Recommended Forum
please resolve my query
Compilation error, metadata file '.dll' could not be found