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 -
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.
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.