Why This error is coming...................
There is already an open datareader is associated with this command which must be closed
Private Sub AppendItem(ByVal Productid As String, ByVal quantity As Integer)
productid1 = Productid
myConnection = New SqlConnection(connectionstring)
myConnection.Open()
Dim TempData As New DataTable
Dim pid As String = ComboBox1.SelectedItem
myCommand1 = New SqlCommand("SELECT P_Selling_Price,Discounted_Price FROM Product_Details WHERE P_Id='" & pid & "' ", myConnection)
myCommand1.ExecuteNonQuery()
'sqlcmd = New SqlCommand("SELECT P_Id,P_Selling_Price FROM Product_Details WHERE P_Id='" & pid & "' ", myConnection)
Dim dr As SqlDataReader = myCommand1.ExecuteReader
dr.Read()
''''''''''''''''''''''''
' For i = 0 To TempData.Rows.Count-1
Dim newItem As New ListViewItem(Productid)
newItem.SubItems.Add(dr("P_Selling_Price"))
newItem.SubItems.Add(dr("Discounted_Price"))
newItem.SubItems.Add(quantity)
newItem.SubItems.Add(dr("P_Selling_Price") * quantity)
' newItem.SubItems.Add()
ListView1.Items.Add(newItem)
' Next
If dr.HasRows Then
'ok
MessageBox.Show("Succesfully updated !!", "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
Else
MessageBox.Show("Data doesn't exits !!", "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
End If
CalTotal()
dr.Close()
Dim productname As String = Product()
Dim insert As SqlCommand = New SqlCommand("Insert into Sells (Bill_No,P_Id,Category,No_Of_Units_sold,Subtotal,Name) values ('" & Val(TextBox14.Text) & "','" & pid & "','" & ComboBox2.SelectedItem & "','" & TextBox1.Text & "','" & TextBox5.Text & "','" & productname & "')", myConnection)
insert.ExecuteNonQuery()
insert.Cancel()
MessageBox.Show("Data is added. !", "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
''''''''''''''''''''''''''''''''''''''''''''''''''''''
myConnection.Close()
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function Product()
Dim pname As String
myConnection = New SqlConnection(Module1.connectionString)
myConnection.Open()
myCommand2 = New SqlCommand("SELECT [Name] FROM [VBP].[dbo].[Product_Name_List] WHERE P_Id='" & ComboBox2.Text & "' ", myConnection)
myCommand2.ExecuteNonQuery()
Dim dr1 As SqlDataReader = myCommand2.ExecuteReader
While dr1.Read()
Debug.WriteLine(dr1(0))
pname = (dr1(0).ToString)
'currentbalance = Double.Parse(dr(2).ToString)
End While
Return (pname)
'' inhere notification is coming the error the varile is using before assiging
dr1.Close()
myConnection.Close()
End Function
Dim productname As String = Product()
In here product name is retriving from product() function