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

You are currently viewing the ASP.NET 3.5 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 May 4th, 2009, 04:57 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

There is no "right solution".... It all depends on your object model, your entities, your data structure and your prior knowledge of this technology.

Without knowing more about your database and object model, I can't recommend much....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old May 4th, 2009, 05:11 AM
Authorized User
 
Join Date: Mar 2009
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Suppose that I've the same structure of your example!

ContactPerson -> JOINED -> MailAddress

1 Person -> X Mail Address


If I have an entity named ContactPerson and I whant to know field's value of INNER JOIN records (of Address table) .... what I have to do??

Thanks
 
Old May 4th, 2009, 05:23 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

There are many ways to do it, but one way is this:

SPROC (all pseudo)

@id int
SELECT * FROM Contact WHERE Id = @id
SELECT * FROM Address WHERE ContactId = @id

This gives you two result sets.

Then in your class Contact class:

// Get a reader based on the sproc
// Fill contact with data from the reader.
// Then fill the contact:
myContact.Address = new Address(myReader.NextResult());

The Address constructor accepts a IDataReader that it uses to fill in the data.

For more info on NextResult: http://msdn.microsoft.com/en-us/libr...extresult.aspx

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old May 4th, 2009, 05:13 PM
Authorized User
 
Join Date: Mar 2009
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Excuse me Imar.... I've made many test

using the objects of your example


ContactPerson contact = new ContactPerson();

contact = ContactPersonManager.GetItem(4);

now I've "contact" .... how can I view the addresses linked ?

Thanks
 
Old May 5th, 2009, 03:47 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Have you read the 6-part article series that goes with the code download? The article is the main asset; the code just a working example of what's exaplained in the articles. You shouldn't just download and use the code without understanding what it's all about.

If you read the articles closely, you find somehting like:

myContact.Addresses

as the answer to your question.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old May 5th, 2009, 03:51 AM
Authorized User
 
Join Date: Mar 2009
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Imar! I've read articles many times ... and now I would like to make test on your example ... for allow me to work on nTier structure ... this is the firt time for me!

Could you help me ... starting with this code

ContactPerson contact = new ContactPerson();

contact = ContactPersonManager.GetItem(4);

now I've "contact" .... how can I view the addresses linked ?

Thanks for help me!!
 
Old May 5th, 2009, 03:54 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I just told you in my previous post:

contact.Addresses

contains eum, well, the addresses.....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old May 5th, 2009, 04:02 AM
Authorized User
 
Join Date: Mar 2009
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks!!!

But I have to cast it? for allow me to do contact.address.something?

address addr = (address)contact.address;

Thanks
 
Old May 5th, 2009, 04:33 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Why would you? Take another look at the source and the articles. You'll see that Addresses is an AddressCollection......

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old May 5th, 2009, 05:36 PM
Authorized User
 
Join Date: Mar 2009
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Uffffff

I've inserted 3 records with ID 2883 in addresses table

but in debug mode I see

- contact.Addresses Count = 0 Spaanjaars.ContactManager.BusinessEntities.Address Collection


but in addresses table I've

66 q q 111 11 11 1 2883 <Binary data>
67 2 2 11 11 11 1 2883 <Binary data>
68 2 2 11 11 11 1 2883 <Binary data>


with this code:

ContactPerson contact = new ContactPerson();

contact = ContactPersonManager.GetItem(2883);





Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy whole structure of table in #temp table maulik77 SQL Server 2000 2 December 21st, 2006 02:42 AM
Copy table structure sagarbhargava SQL Server 2000 3 November 16th, 2006 03:16 AM
Can a Make Table Query produce a Linked table? kronik Access 5 May 16th, 2006 06:17 AM
change table structure Duncan SQL Server 2000 1 March 3rd, 2005 04:10 AM
Printing of Table structure Vanaj SQL Server 2000 4 July 16th, 2004 01:26 AM





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