Solved

DropDownList w/ DataSource - How to Combine 2 Fields (LastName, FirstName)?

Posted on 2002-05-06
8
504 Views
Last Modified: 2007-11-27
Ok, I am using Microsoft SQL With Stored Procedures.  I run a Query that returns the First Name and Last Name of all the users in the Database.  I then return that and try and fill a DropDownList with this Format "Last, First".  I can get just one field to successfully fill, like Last Name, but I can't seem to figure out how to combine Last Name and First Name.

Here is some Code:
1. SQL Calling Stored Procedure
' Execute the command
  myConnection.Open()
  Dim result As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)

' Return the datareader result
  Return result

2. Filling the DropDownList (The Code Below works for Last Name)

Me.ddlStudentDetail.DataSource = dbGradSite.StudentFullName()
Me.ddlStudentDetail.DataValueField = "LastName"
Me.ddlStudentDetail.DataTextField = "LastName"
Me.ddlStudentDetail.DataBind()

Now, as I said before I want "LastName, FirsName".  Any help/advice would be appreciated.

Thanks.
0
Comment
Question by:KrAzY
8 Comments
 
LVL 20

Expert Comment

by:jitganguly
ID: 6992179
You have to concatenate both the fields like

Me.ddlStudentDetail.DataSource = dbGradSite.StudentFullName()
Me.ddlStudentDetail.DataValueField = "LastName"
Me.ddlStudentDetail.DataTextField = "LastName" & " , " & "Firstname"
Me.ddlStudentDetail.DataBind()



0
 
LVL 11

Author Comment

by:KrAzY
ID: 6992446
I tried that and this is what I got:

DataBinder.Eval: 'System.Data.Common.DbDataRecord' does not contain a property with the name LastName , Firstname.
0
 

Expert Comment

by:poxy
ID: 6992524
Is this what you ar looking for?

myConnection.Open()
Dim objRes
set objRes = myConnection.execute("exec sp_something")
while not objRes.eof
  response.write objRes("FirstName")
  response.write objRes("LastName")
  objRes.movenext
wend
0
 
LVL 11

Author Comment

by:KrAzY
ID: 6992674
No that is not what I am looking for...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Accepted Solution

by:
nilapenn earned 150 total points
ID: 6992969
Return LastName and FirstName as a single string from your stored proecdure

for (eg)

Select LastName+","+FristName as FullName from TableName

Then in your code

Me.ddlStudentDetail.DataSource = dbGradSite.StudentFullName()
Me.ddlStudentDetail.DataValueField = "FullName"
Me.ddlStudentDetail.DataTextField = "FullName"
Me.ddlStudentDetail.DataBind()
0
 
LVL 11

Author Comment

by:KrAzY
ID: 6993035
Excellent, that did it.  I had to modify it a little according to MS SQL Syntax:

SELECT
(LastName + ', ' + FirstName) AS FullName
FROM
Students
 
Thanks again.
0
 

Expert Comment

by:Vilas
ID: 6993284
SELECT
(LastName + ' ' + FirstName) AS FullName
FROM
Students

0
 
LVL 11

Author Comment

by:KrAzY
ID: 6993375
Thanks... Vilas, but I already got it from poxy. I wanted the ',' in there to seperate the names.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now