Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Re: Databound Control :Named class versus IEnumerable


Message #1 by "Chris Kersey" <ckersey@m...> on Mon, 17 Jun 2002 13:16:31 -0700
Well, the ultimate reason for using the IEnumerator is as you said to accept
anything that implements IEnumerator.  I don't know if that's actually
necessary.  The client is me and the reason is twofold...  to add it to my
toolbox and to get up to speed with .NET programming.

Realistically speaking, the only applications that I would bother using a
navigation control on would be database driven.  Perhaps I would use XML for
smaller ventures, but I could create another version of the control that
expects xml as opposed to a datareader.

Since it is a navigation control, my main concern is reducing overhead as
much as possible.

Sooooooo.  that said, perhaps I can just assume a *DataReader and use
caching.  I would love to hear any suggestions or recommendations you or
anyone else has.

Thanks sooo much.
Chris

----- Original Message -----
From: "Feduke Cntr Charles R" <FedukeCR@m...>
To: "ASP+" <aspx@p...>
Sent: Monday, June 17, 2002 12:38 PM
Subject: [aspx] Re: Databound Control : GetPropertyValue Only Way To e
xtract data?


> Chris,
>
> Is there any reason why you're using an IEnumerator and not a
> *DataReader or another named class?  Are you trying to make this accept
> anything that implements IEnumerator?  You'd get a bit better performance
> using an actual class (like *DataReader) than you do with a generic
> IEnumerator, but as you said you're looking at 20 records or so each so
the
> performance hit isn't going to be noticeable.
>
> - Chuck
>
> -----Original Message-----
> From: Chris Kersey [mailto:ckersey@m...]
> Sent: Monday, June 17, 2002 2:45 PM
> To: ASP+
> Subject: [aspx] Re: Databound Control : GetPropertyValue Only Way To
> extract data?
>
>
> Checking for DBNull does the trick, thanks.
>
> Does anyone happen to have the answer for the other question I raised
> concerning another way to pull data from the IEnumerable other than using
> GetPropertyValue?  From what I understand that method uses late binding
> (reflection) correct?  As such it would create a heavier overhead.  Or is
> the overhead incurred negligible considering the the application that wil
be
> using it is only a navigation component that will be  pulling about 20
> entries or less on average?
>
> Hmm.. I should probably cache that data now that I'm thinking about it.
> It's application wide and accessed on every page (or will be...)
>
> Thanks for your input.
> Chris
>
>
> ----- Original Message -----
> From: "Feduke Cntr Charles R" <FedukeCR@m...>
> To: "ASP+" <aspx@p...>
> Sent: Monday, June 17, 2002 4:30 AM
> Subject: [aspx] Re: Databound Control : Databind : GetPropertyValue :
> Checking for null && Only Way?
>
>
> > Chris,
> >
> > Aside from the checking for DBNull, you can't implicitly cast
> > something as an int unless its some other numeric data type.  Since
you're
> > probably dealing with an object data type, you might have to go as far
as:
> >
> > // dr = your SqlDataReader
> > int something = Int32.Parse(dr["user_id"].ToString());
> > // or in your case
> > int something2 = Int32.Parse(
> > DataBinder.GetPropertyValue(links.Current,
> > "ParentId").ToString());
> >
> > HTH,
> > - Chuck
> >
> > -----Original Message-----
> > From: Mingkun Goh [mailto:mangokun@h...]
> > Sent: Sunday, June 16, 2002 2:23 PM
> > To: ASP+
> > Subject: [aspx] Re: Databound Control : Databind : GetPropertyValue :
> > Checking for null && Only Way?
> >
> >
> > You can check against any database field for null value using the syntax
> > below:
> > if (data != System.DBNull.Value)
> > {
> >   // Do your stuff
> > }
> >
> > Similarly, you can use the IsDBNull Function
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-
> > us/vblr7/html/vafctisnull.asp
> >
> >
> > Prevous message:
> > > I have 2 questions I'm hoping someone can help me to clear up.  I've
> been
> > creating a databound web control that contains basically 3 properties
(for
> > now) that I'm trying to initialize from the datasource.  According to a
> > wrox
> > book that I have (Professional ASP.NET Server Controls...), I can
declare
> a
> > property named _datasource of type IEnumerable, then assign my resultset
> to
> > this datasource variable and then iterate using the .MoveNext() method.
> >
> > Up to this point, everything is fine and dandy.  I can access the
database
> > column using the following syntax, up to the first GetPropertyValue...
> > after that, my app throws an "invalid cast" exception at the first (int)
> > cast I use...:  I think I have deduced that the problem is that my
> database
> > column is a nullable column and so naturally trying to cast
(int)ParentId
> 
> > null is a nono.
> >
> > Here is some of the source code that is throwing the exception.
> > // IEnumerator links;
> >
> > while(links.MoveNext())
> > {
> >     string Url = (string)Databinder.GetPropertyValue(links.Current,
> "Url");
> >
> >     /* EXCEPTION THROWN ON FOLLOWING: ParentId == null on first pass */
> >     int     ParentId = (int)Databinder.GetPropertyValue(links.Current,
> > "ParentId");
> >     int     LinkId    =  (int)Databinder.GetPropertyValue(links.Current,
> > "LinkId");
> >
> > }
> >
> > Question 1:  is there a way to check for null using the
> > DataBinder.GetPropertyValue in order to avoid an invalid cast error?
> > Question 2:  is there another way to extract values (other than using
> > GetPropertyValue()) from the IEnumerator variable "links"?
> >
> > Thanks,
> > Chris
> >
> >
>
>
>
>

Message #2 by Feduke Cntr Charles R <FedukeCR@m...> on Mon, 17 Jun 2002 16:53:00 -0400
> necessary.  The client is me and the reason is twofold...  to add it to my
> toolbox and to get up to speed with .NET programming.

	Ah, then you should add to your toolbox correctly!  Remember the
rule that the more generic the control, the more [processor] cycles that are
wasted, but the easier it is to program and maintain the source code.  So it
comes down to finding a happy median between performance and maintainability
of code in most cases.

	IMO the correct way to implement what you're doing is to make the
general level control like you have, and then derive classes from the
general level and focus them towards a specific target (i.e. a
OleDbDataReader and a NamedCollection for example).  However, this method
ends up with a multitude of classes that all do the same thing, but look for
specific data types and may or may not use [slower] Reflection depending on
what you're targeting.

	So is it all really worth it?  Another rule to realize is that in an
object oriented programming environment you're going to take performance
hits.  Now this isn't a license to write crappy code, and should give you
even more incentive to write tighter code.  However by writing tighter code
we lose polymorphism and it all comes back to our first rule of generic ==
wasted cycles (but polymorphism is good - however don't make something
polymorphic if you're never going to use it as such).

	In conclusion, its safe to make the realization that [unless you are
a 3rd party custom component developer], object oriented programming
techniques are a tool of neccessity.  If you're probably never going to pass
an ArrayList to your enumeration object then don't waste your time writing
the code to do it.  Write code - and intelligently optimize it - where it
makes sense too.

- Chuck

-----Original Message-----
From: Chris Kersey [mailto:ckersey@m...]
Sent: Monday, June 17, 2002 4:17 PM
To: ASP+
Subject: [aspx] Re: Databound Control :Named class versus IEnumerable


Well, the ultimate reason for using the IEnumerator is as you said to accept
anything that implements IEnumerator.  I don't know if that's actually
necessary.  The client is me and the reason is twofold...  to add it to my
toolbox and to get up to speed with .NET programming.

Realistically speaking, the only applications that I would bother using a
navigation control on would be database driven.  Perhaps I would use XML for
smaller ventures, but I could create another version of the control that
expects xml as opposed to a datareader.

Since it is a navigation control, my main concern is reducing overhead as
much as possible.

Sooooooo.  that said, perhaps I can just assume a *DataReader and use
caching.  I would love to hear any suggestions or recommendations you or
anyone else has.

Thanks sooo much.
Chris

----- Original Message -----
From: "Feduke Cntr Charles R" <FedukeCR@m...>
To: "ASP+" <aspx@p...>
Sent: Monday, June 17, 2002 12:38 PM
Subject: [aspx] Re: Databound Control : GetPropertyValue Only Way To e
xtract data?


> Chris,
>
> Is there any reason why you're using an IEnumerator and not a
> *DataReader or another named class?  Are you trying to make this accept
> anything that implements IEnumerator?  You'd get a bit better performance
> using an actual class (like *DataReader) than you do with a generic
> IEnumerator, but as you said you're looking at 20 records or so each so
the
> performance hit isn't going to be noticeable.
>
> - Chuck
>
> -----Original Message-----
> From: Chris Kersey [mailto:ckersey@m...]
> Sent: Monday, June 17, 2002 2:45 PM
> To: ASP+
> Subject: [aspx] Re: Databound Control : GetPropertyValue Only Way To
> extract data?
>
>
> Checking for DBNull does the trick, thanks.
>
> Does anyone happen to have the answer for the other question I raised
> concerning another way to pull data from the IEnumerable other than using
> GetPropertyValue?  From what I understand that method uses late binding
> (reflection) correct?  As such it would create a heavier overhead.  Or is
> the overhead incurred negligible considering the the application that wil
be
> using it is only a navigation component that will be  pulling about 20
> entries or less on average?
>
> Hmm.. I should probably cache that data now that I'm thinking about it.
> It's application wide and accessed on every page (or will be...)
>
> Thanks for your input.
> Chris
>
>
> ----- Original Message -----
> From: "Feduke Cntr Charles R" <FedukeCR@m...>
> To: "ASP+" <aspx@p...>
> Sent: Monday, June 17, 2002 4:30 AM
> Subject: [aspx] Re: Databound Control : Databind : GetPropertyValue :
> Checking for null && Only Way?
>
>
> > Chris,
> >
> > Aside from the checking for DBNull, you can't implicitly cast
> > something as an int unless its some other numeric data type.  Since
you're
> > probably dealing with an object data type, you might have to go as far
as:
> >
> > // dr = your SqlDataReader
> > int something = Int32.Parse(dr["user_id"].ToString());
> > // or in your case
> > int something2 = Int32.Parse(
> > DataBinder.GetPropertyValue(links.Current,
> > "ParentId").ToString());
> >
> > HTH,
> > - Chuck
> >
> > -----Original Message-----
> > From: Mingkun Goh [mailto:mangokun@h...]
> > Sent: Sunday, June 16, 2002 2:23 PM
> > To: ASP+
> > Subject: [aspx] Re: Databound Control : Databind : GetPropertyValue :
> > Checking for null && Only Way?
> >
> >
> > You can check against any database field for null value using the syntax
> > below:
> > if (data != System.DBNull.Value)
> > {
> >   // Do your stuff
> > }
> >
> > Similarly, you can use the IsDBNull Function
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-
> > us/vblr7/html/vafctisnull.asp
> >
> >
> > Prevous message:
> > > I have 2 questions I'm hoping someone can help me to clear up.  I've
> been
> > creating a databound web control that contains basically 3 properties
(for
> > now) that I'm trying to initialize from the datasource.  According to a
> > wrox
> > book that I have (Professional ASP.NET Server Controls...), I can
declare
> a
> > property named _datasource of type IEnumerable, then assign my resultset
> to
> > this datasource variable and then iterate using the .MoveNext() method.
> >
> > Up to this point, everything is fine and dandy.  I can access the
database
> > column using the following syntax, up to the first GetPropertyValue...
> > after that, my app throws an "invalid cast" exception at the first (int)
> > cast I use...:  I think I have deduced that the problem is that my
> database
> > column is a nullable column and so naturally trying to cast
(int)ParentId
> 
> > null is a nono.
> >
> > Here is some of the source code that is throwing the exception.
> > // IEnumerator links;
> >
> > while(links.MoveNext())
> > {
> >     string Url = (string)Databinder.GetPropertyValue(links.Current,
> "Url");
> >
> >     /* EXCEPTION THROWN ON FOLLOWING: ParentId == null on first pass */
> >     int     ParentId = (int)Databinder.GetPropertyValue(links.Current,
> > "ParentId");
> >     int     LinkId    =  (int)Databinder.GetPropertyValue(links.Current,
> > "LinkId");
> >
> > }
> >
> > Question 1:  is there a way to check for null using the
> > DataBinder.GetPropertyValue in order to avoid an invalid cast error?
> > Question 2:  is there another way to extract values (other than using
> > GetPropertyValue()) from the IEnumerator variable "links"?
> >
> > Thanks,
> > Chris
> >
> >
>
>
>
>



  Return to Index