Last post Jul 18, 2012 10:32 PM by Dino He - MSFT
Jul 17, 2012 04:33 PM|kouts1|LINK
I have a list box that I fill with usernames via sql table.
What I need to do is to change all those usernames to their full name. The problem is that I can't use
displayName because whoever created the acconts in here used username for displayName. What I have been doing is basically;
Dim FName As String = UserPrincipal.Current.GivenName
Dim LName As String = UserPrincipal.Current.Surname
Dim FullName As String = Fname + " " + Lname
So in my code, I fill the listbox from my database like so:
Dim connectionString As String = ConfigurationManager.ConnectionStrings("erLearningConnectionString").ConnectionString
Using mySqlConnection As New SqlConnection(connectionString)
Dim mySqlCommand As New SqlCommand("SELECT A.uName, MAX(T.dueDate) as Date FROM topic_Unit T LEFT JOIN tbl_answers A ON T.quID = A.questionID Where T.dueDate = @date GROUP BY A.uName Order BY A.uName", mySqlConnection)
Dim mySqlDataAdapter As New SqlDataAdapter(mySqlCommand)
Dim myDataSet As New DataSet()
ListBox1.DataSource = myDataSet
ListBox1.DataTextField = "uName"
ListBox1.DataValueField = "uName"
Catch ex As Exception
Label2.Text = ex.Message
How do I loop through all those names duing the binding of the listbox above and change those names to thir full names?
thanks for any help!
Jul 17, 2012 07:37 PM|Mythran|LINK
If you have a table in the database with their user id, first name, and last name, you could user a join in the SQL to join the table to the rest of the SQL and then concatenate the two names together in the SELECT to produce a new field in the results that
you can then bind to using the DataTextField property of the ListBox control. Wow, what a long sentence :P
Jul 18, 2012 10:32 PM|Dino He - MSFT|LINK
You can merge the user name by your query string, and then bind this.
For example :
SELECT LName,RName convert(varchar(max),LName)+convert(varchar(max),RName ) As uName From topic.....