?
Solved

SqlDataReader: How do I hide/show panel if NO RECORD exists in the database?

Posted on 2006-04-19
2
Medium Priority
?
237 Views
Last Modified: 2008-03-17
How do I hide/show panel if NO RECORD exists in the database?

Code:

<script runat="server">
   
    Protected Sub btnCheckAccount_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim MyConnection As SqlConnection
        Dim MyCommand As SqlCommand
        Dim MyReader As SqlDataReader
        Dim IDParam As SqlParameter
        MyConnection = New SqlConnection(ConfigurationManager.AppSettings("MM_CONNECTION_STRING_APDTMain"))
        MyCommand = New SqlCommand()
        MyCommand.CommandText = "SELECT * from vw_MemberStatusCheck WHERE Account = @ID"
        MyCommand.CommandType = CommandType.Text
        MyCommand.Connection = MyConnection
        IDParam = New SqlParameter()
        IDParam.ParameterName = "@ID"
        IDParam.Value = txtAccount.Text
        MyCommand.Parameters.Add(IDParam)
        MyCommand.Connection.Open()
        MyReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection)
        While MyReader.Read
            txtDateExpire.Text = MyReader("DateExpire").ToString()
            txtFirstName.Text = MyReader("FirstName")
            txtMemberType.Text = MyReader("MemberType")
            cbxActive.Checked = MyReader("Active")
            txtAccount.Text = MyReader("Account")
        End While
        If Not MyReader.Read Then
            pnlNoRecords.Visible = True
            pnlActive.Visible = False
            pnlExpired.Visible = False
        Else
        End If
        MyCommand.Dispose()
        MyConnection.Dispose()
        If cbxActive.Checked = True Then
            pnlActive.Visible = True
            pnlNoRecords.Visible = False
        Else

        End If
        If cbxActive.Checked = False Then
            pnlExpired.Visible = True
            pnlNoRecords.Visible = False
            pnlActive.Visible = False
        Else
        End If
       
    End Sub
</script>


<asp:Panel ID="pnlExpired" runat="server" Visible="false">

<p>    
    <asp:Literal ID="txtFirstName" runat="server"></asp:Literal>, it seems
    that your membership with APDT expired on <asp:Literal ID="txtDateExpire" runat="server"></asp:Literal>.&nbsp; Renew now &gt;</p>
    </asp:Panel>
    <asp:Panel ID="pnlActive" runat="server" Visible="false">
<p> You are an active: <asp:Literal ID="txtMemberType" runat="server"></asp:Literal>.</p>
       
    </asp:Panel>
 <asp:CheckBox ID="cbxActive" runat="server" Visible="false"/>
    <asp:Panel ID="pnlNoRecords" runat="server" Visible="false">
<p> No Records Found.  Please enter a valid Member Number.</p>
    </asp:Panel>
0
Comment
Question by:jumpseatnews
2 Comments
 
LVL 15

Accepted Solution

by:
GavinMannion earned 2000 total points
ID: 16485802
Just add in

pnlNoRecords.Visible = True
pnlActive.Visible = False
pnlExpired.Visible = False

While DataReader.Read()
     'You have records so show the right panel and carry on.
End While
0
 

Author Comment

by:jumpseatnews
ID: 16488400
That did the trick!  Thanks GavinMannion.

Chris
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question