Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 9th, 2004, 01:02 PM
Authorized User
 
Join Date: Oct 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataBind/DataSource problem

I have this Code:

myConnection.Open()
CommandText = "SELECT * FROM Students ORDER BY Students.firsName"
myCommand = New SqlCommand(CommandText, myConnection)

chooseStudent.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConne ction)

'Here is the problem
chooseStudent.DataTextField = "firsName" + "|" + "familyName"

chooseStudent.DataValueField = "firsName"

chooseStudent.DataBind()


In this code "chooseStudent" is a DropDownList which contain all students name.

I want that the value of each option (ListItem) will be the first name, But I want that the text will be "firstName" + "|" + "familyName".
(Like "Brad|Pit", "Gorge|Bush" and so......)

How to do it???

 
Old November 10th, 2004, 12:19 AM
Friend of Wrox
 
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Change the select query as follows

select Students.FirstName+'|'+familyName as FullName Students ORDER BY Students.firsName;

then at the DataTextField property set as follows

chooseStudent.DataTextField = "FullName"



It is not how much we do,
but how much love we put in the doing.

-Mother Theresa
 
Old November 10th, 2004, 06:01 AM
Authorized User
 
Join Date: Oct 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

But I want that:

chooseStudent.DataValueField = "firsName"

also


How to do booth???

 
Old November 10th, 2004, 09:15 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

SELECT firsName+'|'+familyName as FullName, firsName FROM Students ORDER BY firsName;

chooseStudent.DataTextField = "FullName"
chooseStudent.DataValueField = "firsName"





Similar Threads
Thread Thread Starter Forum Replies Last Post
Object datasource VS DataSource SoftMind BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 4 July 27th, 2006 10:44 PM
DataBind Problem liorlankri ADO.NET 3 November 2nd, 2004 04:13 PM
MSHFlexGrid with DataSource Problem samryan VB Databases Basics 1 September 10th, 2004 08:06 AM
problem to deploye extended datasource Choose File BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 July 16th, 2004 10:46 AM
Problem reading DataReader after Databind rathbird ADO.NET 1 March 10th, 2004 05:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.