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
Praveen Kumar
NA
235
22.1k
invalid attempt to call checkdataisready when reader is closed
Sep 14 2020 8:57 AM
Hi,
Can someone help me how to fix this problem in vb.net.
Error Message : invalid attempt to call checkdataisready when reader is closed
Private
Sub
txtBarcode_KeyDown(sender
As
System.
Object
, e
As
System.Windows.Forms.KeyEventArgs)
Handles
txtBarcode.KeyDown
Try
If
e.KeyCode = Keys.Enter
Then
con =
New
SqlConnection(cs)
con.Open()
Dim
ctn1
As
String
=
"select * from Company"
cmd =
New
SqlCommand(ctn1)
cmd.Connection = con
rdr = cmd.ExecuteReader()
If
Not
rdr.Read()
Then
MessageBox.Show(
"Add company profile first in master entry"
,
""
, MessageBoxButtons.OK, MessageBoxIcon.Information)
If
(rdr IsNot
Nothing
)
Then
rdr.Close()
End
If
Return
End
If
If
con.State = ConnectionState.Open
Then
con.Close()
End
If
con =
New
SqlConnection(cs)
con.Open()
cmd = con.CreateCommand()
cmd.CommandText =
"SELECT PID,RTRIM(PurchaseUnit),PurchaseCost,RTRIM(ProductCode),RTRIM(ProductName),SalesCost from Product where Barcode=@d1"
cmd.Parameters.AddWithValue(
"@d1"
, txtBarcode.Text)
rdr = cmd.ExecuteReader()
If
rdr.Read()
Then
lblUnit.Visible =
True
txtProductID.Text = rdr.GetValue(0)
lblUnit.Text = rdr.GetValue(1).ToString()
txtPricePerQty.Text = rdr.GetValue(2)
txtProductCode.Text = rdr.GetValue(3).ToString()
cmbProductName.Text = rdr.GetValue(4).ToString()
txtSalesRate.Text = rdr.GetValue(5)
cmbStorageType.SelectedIndex = 0
cmbWarehouse.SelectedIndex = 0
txtQty.Focus()
If
(rdr IsNot
Nothing
)
Then
rdr.Close()
End
If
End
If
If
con.State = ConnectionState.Open
Then
con.Close()
End
If
End
If
Catch
ex
As
Exception
MessageBox.Show(ex.Message,
"Error"
, MessageBoxButtons.OK, MessageBoxIcon.
Error
)
End
Try
End
Sub
Reply
Answers (
8
)
keep insert same records
how to edit data table column header names using c#?