Bind RadioButtonList with Access DB at runtime

Posted on 2006-04-20
Last Modified: 2011-10-03
I can't figure out what I'm doing wrong to bind the value from my access db to the radiobuttonlist.  Please help.

Code Behind:

    Private Sub getUserInfo()
        Dim objConn As New System.Data.OleDb.OleDbConnection(System.Configuration.ConfigurationSettings.AppSettings("DSN"))
        Dim objCmd As System.Data.OleDb.OleDbCommand
        Dim dr As System.Data.OleDb.OleDbDataReader

        objCmd = New System.Data.OleDb.OleDbCommand("SELECT fname, lname, username, street, city, state, zipcode, phone, email, newsletter, moviereviews, christiananswers FROM Members WHERE UserName=@username", objConn)
        objCmd.Parameters.Add("@username", User.Identity.Name)


            dr = objCmd.ExecuteReader

            If dr.HasRows Then
                txtFName.Text = SNH(dr.Item("fname"))
                txtLName.Text = SNH(dr.Item("lname"))
                lblUserName.Text = SNH(dr.Item("username"))
                txtStreet.Text = SNH(dr.Item("street"))
                txtCity.Text = SNH(dr.Item("city"))
                txtState.Text = SNH(dr.Item("state"))
                txtZip.Text = SNH(dr.Item("zipcode"))
                txtPhone.Text = SNH(dr.Item("phone"))
                txtEmail.Text = SNH(dr.Item("email"))
      rdnewsletter.SelectedItem.Value = SNH(dr.Item("newsletter"))
      rdmoviereviews.SelectedItem.Value = SNH(dr.Item("moviereviews"))
      rdchristiananswers.SelectedItem.Value = SNH(dr.Item("christiananswers"))
            End If

        Catch ex As System.Exception
            lblResult.Text = "There was an error accessing your account: " & ex.Message
            lblResult.ForeColor = System.Drawing.Color.Red
        End Try

    End Sub

    Private Function SNH(ByVal arg As Object) As String
        If Microsoft.VisualBasic.IsDBNull(arg) Then Return String.Empty
        Return Microsoft.VisualBasic.Trim(CType(arg, String))
    End Function



<asp:RadioButtonList DataMember="Members" DataTextField="newsletter" DataValueField="newsletter" DataSource='<%# DataBinder.Eval(Container, "newsletter" )%>' ID="rdnewsletter" runat="server" RepeatDirection="Horizontal"></asp:RadioButtonList>
Question by:azyet24
    1 Comment
    LVL 5

    Accepted Solution

    HI there,

    There is heaps of articles on this, have a look see how you go. It's 2am where I live so i'm going to bed. I should be online tomorrow.


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    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…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video discusses moving either the default database or any database to a new volume.

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now