Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #11 (permalink)  
Old May 4th, 2009, 04:57 AM
Imar's Avatar
Wrox Author
Points: 71,632, Level: 100
Points: 71,632, Level: 100 Points: 71,632, Level: 100 Points: 71,632, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,011
Thanks: 79
Thanked 1,576 Times in 1,553 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!
  #12 (permalink)  
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
  #13 (permalink)  
Old May 4th, 2009, 05:23 AM
Imar's Avatar
Wrox Author
Points: 71,632, Level: 100
Points: 71,632, Level: 100 Points: 71,632, Level: 100 Points: 71,632, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,011
Thanks: 79
Thanked 1,576 Times in 1,553 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!
  #14 (permalink)  
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
  #15 (permalink)  
Old May 5th, 2009, 03:47 AM
Imar's Avatar
Wrox Author
Points: 71,632, Level: 100
Points: 71,632, Level: 100 Points: 71,632, Level: 100 Points: 71,632, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,011
Thanks: 79
Thanked 1,576 Times in 1,553 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!
  #16 (permalink)  
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!!
  #17 (permalink)  
Old May 5th, 2009, 03:54 AM
Imar's Avatar
Wrox Author
Points: 71,632, Level: 100
Points: 71,632, Level: 100 Points: 71,632, Level: 100 Points: 71,632, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,011
Thanks: 79
Thanked 1,576 Times in 1,553 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!
  #18 (permalink)  
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
  #19 (permalink)  
Old May 5th, 2009, 04:33 AM
Imar's Avatar
Wrox Author
Points: 71,632, Level: 100
Points: 71,632, Level: 100 Points: 71,632, Level: 100 Points: 71,632, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,011
Thanks: 79
Thanked 1,576 Times in 1,553 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!
  #20 (permalink)  
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);
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 01:42 AM
Copy table structure sagarbhargava SQL Server 2000 3 November 16th, 2006 02: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 03:10 AM
Printing of Table structure Vanaj SQL Server 2000 4 July 16th, 2004 01:26 AM



All times are GMT -4. The time now is 09:20 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.