Solved

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

Posted on 2002-05-06
8
505 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
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
LVL 11

Author Comment

by:KrAzY
ID: 6992674
No that is not what I am looking for...
0
 
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 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