Solved

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

Posted on 2002-05-06
8
502 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

13 Experts available now in Live!

Get 1:1 Help Now