can anyone help me about this error. "Invalid attempt to call metadata when reader is closed". Thnx in advance.

Public Sub DisplayCust(ByVal lv As ListView)
        If cnSQL.State = ConnectionState.Open Then cnSQL.Close()
        cmd = cnSQL.CreateCommand
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "sp_DisplayCust"

        Dim param = New SqlClient.SqlParameter
        param.ParameterName = "@cust_no"
        param.SqlDbType = SqlDbType.VarChar
        param.Value = lv.SelectedItems(0).Text

        objRead = cmd.ExecuteReader

              While objRead.Read()
                  With frmCustomer
                    .txtCustCode.Text = (objRead("cust_no") & "")
                    .cmbSM.Text = (objRead("sm_name") & "")
                    .txtCustname.Text = (objRead("cust_name") & "") < Error in this line
                    .txtaddress.Text = (objRead("address") & "")
                    .txtRemarks.Text = (objRead("remarks") & "")
                    .txtEmail.Text = (objRead("email_add") & "")
                    End With
                End While
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Data Error")
            Exit Sub
        End Try
    End Sub

Does 'cust_name' exist in the returning table?
Does the error occur on the first iteration or later?

See what happens if you expand the Try..Catch with a Finally and put objRead.Close() and cnSQL.Close() inside that.

This article has been dead for over six months. Start a new discussion instead.