Link to home
Start Free TrialLog in
Avatar of KentDBerry
KentDBerry

asked on

How to set an unbound textbox to value of a datatable

In the below code the IsLoggedOn() function sets the two global variables gbAdmin and gbDeveloper to True/False.  I have two unbound textboxes that I want to set to the values based on who is logged in.

The below code generates the following error:  NullReferenceException Occurred on the me.txtUsername.Text line of code

What do I need to do to resolve?
Public Sub New()
 
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
 
        ' Add any initialization after the InitializeComponent() call.
        IsLoggedOn()
 
        Me.TblApplicationParametersTableAdapter.Fill(Me.BRDWorkslatesDataSet.tblApplicationParameters)
        Me.TblReportOptionsTableAdapter.Fill(Me.ReportOptions.tblReportOptions)
 
        If gbAdmin = True Then
            Me.txtUserName.Text = Me.BRDWorkslatesDataSet.tblApplicationParameters.Columns("AdminUserNameColumn").ToString
            Me.txtPassword.Text = Me.BRDWorkslatesDataSet.tblApplicationParameters.Columns("AdminPasswordColumn").ToString
        ElseIf gbDeveloper = True Then
            Me.txtUserName.Text = Me.BRDWorkslatesDataSet.tblApplicationParameters.Columns("DeveloperUserNameColumn").ToString
            Me.txtPassword.Text = Me.BRDWorkslatesDataSet.tblApplicationParameters.Columns("DeveloperPasswordColumn").ToString
        End If
    End Sub

Open in new window

Avatar of Bob Learned
Bob Learned
Flag of United States of America image

I would guess that either the 'AdminUserNameColumn' or the 'DeveloperUserNameColumn' is an invalid name.

Bob
Avatar of KentDBerry
KentDBerry

ASKER

Bob,

thx.  You are correct, so I changed the line to the following, and I now get "AdminUserName" returned as the value.  If I want to return the value of the data what would I have to do.

            Me.txtUserName.Text = Me.BRDWorkslatesDataSet.tblApplicationParameters.Columns("AdminUserName").ToString
            Me.txtPassword.Text = Me.BRDWorkslatesDataSet.tblApplicationParameters.Columns("AdminPassword").ToString

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial