Solved

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

Posted on 2002-05-06
8
507 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 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
RegEx Help - open to other simple suggestions 8 66
Hide cell in a table 2 45
edit .asp files 5 64
JSON Error in ASP Page 3 39
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…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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