Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2002-05-06
8
Medium Priority
?
511 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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 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 informatio…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

715 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