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

KentDBerryAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Bob
0
KentDBerryAuthor Commented:
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

0
Bob LearnedCommented:
To get data from a DataTable, you need to get the DataRow that you want, and then get the data from that.

Simplified example:

Dim dt As DataTable = Me.DataSet1.Tables("Table1")
Dim dr As DataRow = dt.Rows(0)
Dim value As String = dr("Value").ToString()

In your case, you would need to use the BRDWorkslatesDataSet (DataSet), tblApplicationParameters (DataTable) and AdminUserName (column name).

Bob
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.