Question Testbox display from user login

josh2009

Member
Joined
Sep 16, 2009
Messages
14
Programming Experience
Beginner
Working on a change management application for system changes. I have a field for Requestor (varchar 30) that I am attempting to fill in automatically based on the login id when the user clicks on the Add record (+) button in the Binding Navigator. Here is my code -

VB.NET:
Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click
        Dim Sqlconn As New SqlClient.SqlConnection
        Dim UserID As String
        Sqlconn.ConnectionString = "Data Source=newsource; Database=ProdData; Integrated Security=true"
        UserID = GetUserID()

        Dim Sqlcomm As New SqlClient.SqlCommand("select list_user, propertyvalue from ss_userlist a inner join ss_userproperties b on a.ss_user_id = b.ss_user_id where list_user = '" & UserID & "'", Sqlconn)
        Dim username As String
        Sqlconn.Open()

        Dim r As SqlDataReader = Sqlcomm.ExecuteReader()
        While r.Read
            username = CStr(r("propertyvalue"))
            Me.Text = "Change Management" + " - " + username + " - " + "(" + UserID + ")"
            Me.txtRequestor.Text = username
        End While
        r.Close()
        Sqlconn.Close()

        txtRequestor.Refresh()
        MsgBox("Username is ", vbExclamation, username)
        MsgBox("txtRequestor Text is ", vbExclamation, txtRequestor.Text)

    End Sub

Using this code, I cannot get the Requestor text box to fill in automatically when I click on the (+) button. I've added MsgBox code and both messages give me the correct username. I also use the same code for displaying the user name as the form's title text and it works just fine so I am at a loss why it wouldn't populate the text box. When I manually enter a name in the Requestor field and save the record, the field entry gets populated in the database. Being the newbie that I am, I couldn't figure out what's wrong with my code. Any help will be greatly appreciated. Thanks.
 
I'd just, when the app logs in and at whatever point that you know the Requestor, just do:

MyDataSet.MyTable.RequestorColumn.DefaultValue = "the user name"

Now every row that is ever added to that table will have that default value
 
Back
Top