Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 September 24th, 2007, 02:48 AM
Authorized User
 
Join Date: Sep 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

|| is the string concatenation operator in PostgreSQL (probably the equivalent for SQL Server is +). I've placed the concatenation in parenthesis just to make it look pretty.

Finally, "as Combined" basically means something like "name the field as 'Combined' in the resulting set". So, if you'd execute that, you'd see something like this:

Name | Email | Combined
--------------------------------------
foo | [email protected] | foo [email protected]
bar | [email protected] | bar [email protected]
...

In PostgreSQL if I don't do the "as Combined", the resulting field name would be "?column?", which I must say, isn't that pretty.
 
Old September 24th, 2007, 03:06 AM
Authorized User
 
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to yukijocelyn
Default

Thank you for replying.
if i want to display the combined one, then whe the user have selected, i'll take this value, then connect to the database again to retrieve the email address?


 
Old September 24th, 2007, 03:12 AM
Authorized User
 
Join Date: Sep 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Eh... Not exactly. :)

Just do what you have already done (combined the name and email address) , but in addition, select those two fields separately, so you can access them.

Now, I think you have something like this:

SELECT PK, Name + ' ' + Email From MyTable

You change it to:

SELECT PK, Name + ' ' + Email, Name, Email From MyTable

After that, I think you have what you wanted: you have name & email fields combined for display in DropDownList and you can access name and email separately if you need.
 
Old September 24th, 2007, 03:37 AM
Authorized User
 
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to yukijocelyn
Default

Hi! Thanks again for replying.
I have another concern uprising from this statement.
SELECT PK, Name + ' ' + Email, Name, Email From MyTable
If I use this Name+" "+Email, won't the database think that I'm extracting from the field "Name Email"? Then won't this give me an error saying that they cannot find this field?

 
Old September 24th, 2007, 03:45 AM
Authorized User
 
Join Date: Sep 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Technically speaking the database will think you want to select a field, which is a result of concatenating fields Name AND Email. So, the answer is no, it won't think that you are selecting a field "Name Email", which doesn't exist.

Have you considered trying it out, just to see what it produces? :)
 
Old September 24th, 2007, 03:48 AM
Authorized User
 
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to yukijocelyn
Default

Thanks again for your fast reply. My concern happened.
The database told me that there was an error in retrieving "Name Email".

 
Old September 24th, 2007, 04:02 AM
Authorized User
 
Join Date: Sep 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmm... That's weird. It works with PostgreSQL though and the syntax shouldn't be much different with SQL Server. Are you sure you got the column names right in your SQL query?

I actually did this in SQL Server Express and it worked:

CREATE TABLE Customers (
  Name VARCHAR(255),
  Email VARCHAR(255)
);

INSERT INTO Customers (Name, Email) VALUES ('foo', '[email protected]');

And finally, SELECT Name, Email, (Name + ' ' + Email) AS Combined FROM Customers, which resulted in:

Name Email Combined
----------------------------------
foo [email protected] foo [email protected]

And make sure that you use single quote, not double quote. :) Name + " " + Email won't work, but Name + ' ' + Email works.
 
Old September 24th, 2007, 04:25 AM
Authorized User
 
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to yukijocelyn
Default

Thanks! I'll try them now.

 
Old September 24th, 2007, 04:36 AM
Authorized User
 
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to yukijocelyn
Default

Hey Miko2!
Thank you! It works! Yup, I used the double quotes & typed the Combined in caps, that's why it didn't work. However, when I choose the say particularly Remy|[email protected], how do I reference to "[email protected]" if I don't refer back to the DB again?
Thank you so much!

 
Old September 24th, 2007, 05:19 AM
Authorized User
 
Join Date: Sep 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Eehm... I think I didn't quite think that far about this. As you select the "Remy|[email protected]" item from the DropDownList and submit the form, of course you need to access the database again to retrieve the email address for that particular entry based on the DropDownList's SelectedValue property.

You probably could read the email address from the datasource, but I'm not sure how or even if it's the preferred way of doing it.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple views of single table jatatman ASP.NET 3.5 Basics 1 June 2nd, 2008 01:34 AM
converting Access 2000 views to Sql views matta Classic ASP Professional 1 January 26th, 2005 03:37 PM
Empty table for dropdownlist. macupryk BOOK: ASP.NET Website Programming Problem-Design-Solution 2 August 16th, 2004 06:33 AM
selected value from dropdownlist control netwizard_01 ASP.NET 1.0 and 1.1 Basics 3 January 20th, 2004 09:29 AM
DropDownList control bmains ASP.NET 1.0 and 1.1 Basics 4 November 21st, 2003 01:23 PM





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