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