| Home | Forums | Reviews | Articles | Register |
![]() |
| Thread Tools | Rate Thread |
|
|
|
| |
|
Steven Cheng[MSFT]
Guest
Posts: n/a
|
Hi MC,
From your description, you're using databinding to populate the Adrotator control but found that if you manually bind DataReader to it, it will always miss the first record, correct? I've performed some test and repro this behavior. After some further research, I found out the cause of the problem. It is because the AdRotator will try dynamically inspect the datasource item's property list. It will use the following code(get from reflector). You can see that for those datasource objects which do not support "ITypedList.GetItemProperties", it will read a row(the first row) so as to get all the fields(columns) info. And for datareader, this is exact the case and the first row is used for getting fields info and not used at the databinding later. >>>>>>>>>>>>>>>> private ArrayList CreateAutoGeneratedFields(IEnumerable dataSource) { if (dataSource == null) { return null; } ArrayList list = new ArrayList(); PropertyDescriptorCollection itemProperties = null; if (dataSource is ITypedList) { itemProperties = ((ITypedList) dataSource).GetItemProperties(new PropertyDescriptor[0]); } if (itemProperties == null) { IEnumerator enumerator = dataSource.GetEnumerator(); if (enumerator.MoveNext()) { object current = enumerator.Current; if (this.IsBindableType(current.GetType())) { throw new HttpException(SR.GetString("AdRotator_expect_records_with_advertisement_prop erties", new object[] { this.ID, current.GetType() })); } itemProperties = TypeDescriptor.GetProperties(current); } } if ((itemProperties != null) && (itemProperties.Count > 0)) { foreach (PropertyDescriptor descriptor in itemProperties) { if (this.IsBindableType(descriptor.PropertyType)) { list.Add(descriptor.Name); } } } return list; } <<<<<<<<<<<<<<<<<<<<<<<<<< I've also found a means to resolve this. If you do not want to directly return DataSet from ADO.NET query. You can manualy create a DataTable object to wrapper the records(from DataReader). Here is a sample function show this: ======================== protected void BindRorator2() { string sql = "SELECT [id], [name], [description] FROM [itemtable]"; using (SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["DatabaseConnectionS tring"].ConnectionString)) { conn.Open(); using(SqlCommand comm = new SqlCommand(sql, conn)) { SqlDataReader reader = comm.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(reader); this.AdRotator2.DataSource = dt; this.AdRotator2.DataBind(); reader.Close(); } } } =============================== Hope this helps. Sincerely, Steven Cheng Microsoft MSDN Online Support Lead ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...ult.aspx#notif ications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscripti...t/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. -------------------- >From: MC <(E-Mail Removed)> >Newsgroups: microsoft.public.dotnet.framework.aspnet >Subject: AdRotator Problem >Date: Sat, 06 Oct 2007 11:40:22 GMT > >I have coded an AdRotator to use a Database for it's data source. If I >use a SqlDataSource control it functions as expected, however if I >manually retreive the data using an OleDBDataReader It always omits the >first item in the result set? Code for each solution as below. > >The reason I'm don't want to use the Declarative solution is that I >intend to Create a custom control that inherits from AdRotator and I >would then need to retrieve the Advert set programtically. > >Regards > > >MC > >------------------- Solution 1 - Declarative ------------------- > ><asp:Content ID="Content2" ContentPlaceHolderID="cphMainSite" >Runat="Server"> > <asp:SqlDataSource ID="SqlDataSource1" runat="server" >ConnectionString="<%$ ConnectionStrings:AdsDatabase %>" >ProviderName="<%$ ConnectionStrings:AdsDatabase.ProviderName %>" >SelectCommand="SELECT CompanyName AS ImageUrl, CompanyName AS >AlternateText, URL AS NavigateUrl, Impressions, Clicks FROM Sponsors >WHERE BannerAdvert=True" /> > <asp:AdRotator ID="AdRotator1" runat="server" >DataSourceID="SqlDataSource1" /> ></asp:Content> > >------------------- Solution 2 - OleDBReader ------------------- > ><script runat="server"> > protected void Page_Load(object sender, EventArgs e) > { > using (System.Data.OleDb.OleDbConnection conn = new >System.Data.OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings["A dsDatabase"].ConnectionString)) > { > conn.Open(); > using (System.Data.OleDb.OleDbCommand comm = new >System.Data.OleDb.OleDbCommand("SELECT CompanyName AS ImageUrl, >CompanyName AS AlternateText, URL AS NavigateUrl, Impressions, Clicks >FROM Sponsors WHERE BannerAdvert=True", conn)) > { > AdRotator1.DataSource = comm.ExecuteReader(); > AdRotator1.DataBind(); > } > } > } ></script> ><asp:Content ID="Content2" ContentPlaceHolderID="cphMainSite" >Runat="Server"> > <asp:AdRotator ID="AdRotator1" runat="server" /> ></asp:Content> > |
|
||
|
||||
|
Steven Cheng[MSFT]
Guest
Posts: n/a
|
Hi MC,
How are you doing? Does the info in my last reply help you on this issue? If there is anything else we can help, please feel free to post here. Sincerely, Steven Cheng Microsoft MSDN Online Support Lead This posting is provided "AS IS" with no warranties, and confers no rights. -------------------- >From: (E-Mail Removed) (Steven Cheng[MSFT]) >Organization: Microsoft >Date: Mon, 08 Oct 2007 07:32:33 GMT >Subject: RE: AdRotator Problem >Hi MC, > >From your description, you're using databinding to populate the Adrotator >control but found that if you manually bind DataReader to it, it will >always miss the first record, correct? > >I've performed some test and repro this behavior. After some further >research, I found out the cause of the problem. It is because the AdRotator >will try dynamically inspect the datasource item's property list. It will >use the following code(get from reflector). > >You can see that for those datasource objects which do not support >"ITypedList.GetItemProperties", it will read a row(the first row) so as to >get all the fields(columns) info. And for datareader, this is exact the >case and the first row is used for getting fields info and not used at the >databinding later. > >>>>>>>>>>>>>>>>> >private ArrayList CreateAutoGeneratedFields(IEnumerable dataSource) >{ > if (dataSource == null) > { > return null; > } > ArrayList list = new ArrayList(); > PropertyDescriptorCollection itemProperties = null; > if (dataSource is ITypedList) > { > itemProperties = ((ITypedList) dataSource).GetItemProperties(new >PropertyDescriptor[0]); > } > if (itemProperties == null) > { > IEnumerator enumerator = dataSource.GetEnumerator(); > if (enumerator.MoveNext()) > { > object current = enumerator.Current; > if (this.IsBindableType(current.GetType())) > { > throw new >HttpException(SR.GetString("AdRotator_expect_records_with_advertisement_pro p >erties", new object[] { this.ID, current.GetType() })); > } > itemProperties = TypeDescriptor.GetProperties(current); > } > } > if ((itemProperties != null) && (itemProperties.Count > 0)) > { > foreach (PropertyDescriptor descriptor in itemProperties) > { > if (this.IsBindableType(descriptor.PropertyType)) > { > list.Add(descriptor.Name); > } > } > } > return list; >} > > ><<<<<<<<<<<<<<<<<<<<<<<<<< > >I've also found a means to resolve this. If you do not want to directly >return DataSet from ADO.NET query. You can manualy create a DataTable >object to wrapper the records(from DataReader). Here is a sample function >show this: > >======================== > protected void BindRorator2() > { > string sql = "SELECT [id], [name], [description] FROM [itemtable]"; > > using (SqlConnection conn = new >SqlConnection(WebConfigurationManager.ConnectionStrings["DatabaseConnection S >tring"].ConnectionString)) > { > conn.Open(); > > using(SqlCommand comm = new SqlCommand(sql, conn)) > { > SqlDataReader reader = comm.ExecuteReader(); > DataTable dt = new DataTable(); > dt.Load(reader); > > this.AdRotator2.DataSource = dt; > this.AdRotator2.DataBind(); > > reader.Close(); > > } > > } > } >=============================== > >Hope this helps. > >Sincerely, > >Steven Cheng > >Microsoft MSDN Online Support Lead > > > >================================================== > >Get notification to my posts through email? Please refer to >http://msdn.microsoft.com/subscripti...ault.aspx#noti f >ications. > > > >Note: The MSDN Managed Newsgroup support offering is for non-urgent issues >where an initial response from the community or a Microsoft Support >Engineer within 1 business day is acceptable. Please note that each follow >up response may take approximately 2 business days as the support >professional working with you may need further investigation to reach the >most efficient resolution. The offering is not appropriate for situations >that require urgent, real-time or phone-based interactions or complex >project analysis and dump analysis issues. Issues of this nature are best >handled working with a dedicated Microsoft Support Engineer by contacting >Microsoft Customer Support Services (CSS) at >http://msdn.microsoft.com/subscripti...t/default.aspx. > >================================================== > > >This posting is provided "AS IS" with no warranties, and confers no rights. > > >-------------------- >>From: MC <(E-Mail Removed)> >>Newsgroups: microsoft.public.dotnet.framework.aspnet >>Subject: AdRotator Problem >>Date: Sat, 06 Oct 2007 11:40:22 GMT > >> >>I have coded an AdRotator to use a Database for it's data source. If I >>use a SqlDataSource control it functions as expected, however if I >>manually retreive the data using an OleDBDataReader It always omits the >>first item in the result set? Code for each solution as below. >> >>The reason I'm don't want to use the Declarative solution is that I >>intend to Create a custom control that inherits from AdRotator and I >>would then need to retrieve the Advert set programtically. >> >>Regards >> >> >>MC >> >>------------------- Solution 1 - Declarative ------------------- >> >><asp:Content ID="Content2" ContentPlaceHolderID="cphMainSite" >>Runat="Server"> >> <asp:SqlDataSource ID="SqlDataSource1" runat="server" >>ConnectionString="<%$ ConnectionStrings:AdsDatabase %>" >>ProviderName="<%$ ConnectionStrings:AdsDatabase.ProviderName %>" >>SelectCommand="SELECT CompanyName AS ImageUrl, CompanyName AS >>AlternateText, URL AS NavigateUrl, Impressions, Clicks FROM Sponsors >>WHERE BannerAdvert=True" /> >> <asp:AdRotator ID="AdRotator1" runat="server" >>DataSourceID="SqlDataSource1" /> >></asp:Content> >> >>------------------- Solution 2 - OleDBReader ------------------- >> >><script runat="server"> >> protected void Page_Load(object sender, EventArgs e) >> { >> using (System.Data.OleDb.OleDbConnection conn = new >>System.Data.OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings[" A >dsDatabase"].ConnectionString)) >> { >> conn.Open(); >> using (System.Data.OleDb.OleDbCommand comm = new >>System.Data.OleDb.OleDbCommand("SELECT CompanyName AS ImageUrl, >>CompanyName AS AlternateText, URL AS NavigateUrl, Impressions, Clicks >>FROM Sponsors WHERE BannerAdvert=True", conn)) >> { >> AdRotator1.DataSource = comm.ExecuteReader(); >> AdRotator1.DataBind(); >> } >> } >> } >></script> >><asp:Content ID="Content2" ContentPlaceHolderID="cphMainSite" >>Runat="Server"> >> <asp:AdRotator ID="AdRotator1" runat="server" /> >></asp:Content> >> > > |
|
||
|
||||
|
MC
Guest
Posts: n/a
|
Steven,
Thanks for the info, I have solved it using a slightly different approach. My goal was to implement a customcotrol and I have now done this using a composite control which contains two child controls a SqlDataSource and the AdRotator. This now works well. However I have a new Problem which I have posted as a new thread. In the Building Controls newsgroup Regards MC Steven Cheng[MSFT] wrote: > Hi MC, > > How are you doing? > > Does the info in my last reply help you on this issue? If there is anything > else we can help, please feel free to post here. > > Sincerely, > > Steven Cheng > > Microsoft MSDN Online Support Lead > > > This posting is provided "AS IS" with no warranties, and confers no rights. > -------------------- > >> From: (E-Mail Removed) (Steven Cheng[MSFT]) >> Organization: Microsoft >> Date: Mon, 08 Oct 2007 07:32:33 GMT >> Subject: RE: AdRotator Problem > >> Hi MC, >> >>From your description, you're using databinding to populate the Adrotator >> control but found that if you manually bind DataReader to it, it will >> always miss the first record, correct? >> >> I've performed some test and repro this behavior. After some further >> research, I found out the cause of the problem. It is because the > AdRotator >> will try dynamically inspect the datasource item's property list. It will >> use the following code(get from reflector). >> >> You can see that for those datasource objects which do not support >> "ITypedList.GetItemProperties", it will read a row(the first row) so as to >> get all the fields(columns) info. And for datareader, this is exact the >> case and the first row is used for getting fields info and not used at the >> databinding later. >> >> private ArrayList CreateAutoGeneratedFields(IEnumerable dataSource) >> { >> if (dataSource == null) >> { >> return null; >> } >> ArrayList list = new ArrayList(); >> PropertyDescriptorCollection itemProperties = null; >> if (dataSource is ITypedList) >> { >> itemProperties = ((ITypedList) dataSource).GetItemProperties(new >> PropertyDescriptor[0]); >> } >> if (itemProperties == null) >> { >> IEnumerator enumerator = dataSource.GetEnumerator(); >> if (enumerator.MoveNext()) >> { >> object current = enumerator.Current; >> if (this.IsBindableType(current.GetType())) >> { >> throw new >> HttpException(SR.GetString("AdRotator_expect_records_with_advertisement_pro > p >> erties", new object[] { this.ID, current.GetType() })); >> } >> itemProperties = TypeDescriptor.GetProperties(current); >> } >> } >> if ((itemProperties != null) && (itemProperties.Count > 0)) >> { >> foreach (PropertyDescriptor descriptor in itemProperties) >> { >> if (this.IsBindableType(descriptor.PropertyType)) >> { >> list.Add(descriptor.Name); >> } >> } >> } >> return list; >> } >> >> >> <<<<<<<<<<<<<<<<<<<<<<<<<< >> >> I've also found a means to resolve this. If you do not want to directly >> return DataSet from ADO.NET query. You can manualy create a DataTable >> object to wrapper the records(from DataReader). Here is a sample function >> show this: >> >> ======================== >> protected void BindRorator2() >> { >> string sql = "SELECT [id], [name], [description] FROM [itemtable]"; >> >> using (SqlConnection conn = new >> SqlConnection(WebConfigurationManager.ConnectionStrings["DatabaseConnection > S >> tring"].ConnectionString)) >> { >> conn.Open(); >> >> using(SqlCommand comm = new SqlCommand(sql, conn)) >> { >> SqlDataReader reader = comm.ExecuteReader(); >> DataTable dt = new DataTable(); >> dt.Load(reader); >> >> this.AdRotator2.DataSource = dt; >> this.AdRotator2.DataBind(); >> >> reader.Close(); >> >> } >> >> } >> } >> =============================== >> >> Hope this helps. >> >> Sincerely, >> >> Steven Cheng >> >> Microsoft MSDN Online Support Lead >> >> >> >> ================================================== >> >> Get notification to my posts through email? Please refer to >> http://msdn.microsoft.com/subscripti...ault.aspx#noti > f >> ications. >> >> >> >> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues >> where an initial response from the community or a Microsoft Support >> Engineer within 1 business day is acceptable. Please note that each follow >> up response may take approximately 2 business days as the support >> professional working with you may need further investigation to reach the >> most efficient resolution. The offering is not appropriate for situations >> that require urgent, real-time or phone-based interactions or complex >> project analysis and dump analysis issues. Issues of this nature are best >> handled working with a dedicated Microsoft Support Engineer by contacting >> Microsoft Customer Support Services (CSS) at >> http://msdn.microsoft.com/subscripti...t/default.aspx. >> >> ================================================== >> >> >> This posting is provided "AS IS" with no warranties, and confers no rights. >> >> >> -------------------- >>> From: MC <(E-Mail Removed)> >>> Newsgroups: microsoft.public.dotnet.framework.aspnet >>> Subject: AdRotator Problem >>> Date: Sat, 06 Oct 2007 11:40:22 GMT >>> I have coded an AdRotator to use a Database for it's data source. If I >>> use a SqlDataSource control it functions as expected, however if I >>> manually retreive the data using an OleDBDataReader It always omits the >>> first item in the result set? Code for each solution as below. >>> >>> The reason I'm don't want to use the Declarative solution is that I >>> intend to Create a custom control that inherits from AdRotator and I >>> would then need to retrieve the Advert set programtically. >>> >>> Regards >>> >>> >>> MC >>> >>> ------------------- Solution 1 - Declarative ------------------- >>> >>> <asp:Content ID="Content2" ContentPlaceHolderID="cphMainSite" >>> Runat="Server"> >>> <asp:SqlDataSource ID="SqlDataSource1" runat="server" >>> ConnectionString="<%$ ConnectionStrings:AdsDatabase %>" >>> ProviderName="<%$ ConnectionStrings:AdsDatabase.ProviderName %>" >>> SelectCommand="SELECT CompanyName AS ImageUrl, CompanyName AS >>> AlternateText, URL AS NavigateUrl, Impressions, Clicks FROM Sponsors >>> WHERE BannerAdvert=True" /> >>> <asp:AdRotator ID="AdRotator1" runat="server" >>> DataSourceID="SqlDataSource1" /> >>> </asp:Content> >>> >>> ------------------- Solution 2 - OleDBReader ------------------- >>> >>> <script runat="server"> >>> protected void Page_Load(object sender, EventArgs e) >>> { >>> using (System.Data.OleDb.OleDbConnection conn = new >>> System.Data.OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings[" > A >> dsDatabase"].ConnectionString)) >>> { >>> conn.Open(); >>> using (System.Data.OleDb.OleDbCommand comm = new >>> System.Data.OleDb.OleDbCommand("SELECT CompanyName AS ImageUrl, >>> CompanyName AS AlternateText, URL AS NavigateUrl, Impressions, Clicks >> >FROM Sponsors WHERE BannerAdvert=True", conn)) >>> { >>> AdRotator1.DataSource = comm.ExecuteReader(); >>> AdRotator1.DataBind(); >>> } >>> } >>> } >>> </script> >>> <asp:Content ID="Content2" ContentPlaceHolderID="cphMainSite" >>> Runat="Server"> >>> <asp:AdRotator ID="AdRotator1" runat="server" /> >>> </asp:Content> >>> >> > |
|
||
|
||||
|
Steven Cheng[MSFT]
Guest
Posts: n/a
|
Thanks for your followup MC,
I'm glad that you've also found means to resolve this problem. Yes, I've seen your another thread in control newsgroup, and many community members have joined it. I'll also have a look there. Sincerely, Steven Cheng Microsoft MSDN Online Support Lead This posting is provided "AS IS" with no warranties, and confers no rights. -------------------- >From: MC <(E-Mail Removed)> >Newsgroups: microsoft.public.dotnet.framework.aspnet >Subject: Re: AdRotator Problem >Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTFEEDS02.phx.gbl!newsfeed0 0.sul.t-online.de!t-online.de!feeder.news-service.com!feeder.news-service.co m!216.196.110.148.MISMATCH!border1.nntp.ams.giganews.com!nntp.giganews.com!n ews-in.ntli.net!newsrout1-win.ntli.net!ntli.net!news.highwinds-media.com!new speer1-win.ntli.net!newsfe2-win.ntli.net.POSTED!53ab2750!not-for-mail >Xref: TK2MSFTNGHUB02.phx.gbl microsoft.public.dotnet.framework.aspnet:45933 >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet > >Steven, > >Thanks for the info, I have solved it using a slightly different >approach. My goal was to implement a customcotrol and I have now done >this using a composite control which contains two child controls a >SqlDataSource and the AdRotator. This now works well. However I have a >new Problem which I have posted as a new thread. In the Building >Controls newsgroup > >Regards > >MC > >Steven Cheng[MSFT] wrote: >> Hi MC, >> >> How are you doing? >> >> Does the info in my last reply help you on this issue? If there is anything >> else we can help, please feel free to post here. >> >> Sincerely, >> >> Steven Cheng >> >> Microsoft MSDN Online Support Lead >> >> >> This posting is provided "AS IS" with no warranties, and confers no rights. >> -------------------- >> >>> From: (E-Mail Removed) (Steven Cheng[MSFT]) >>> Organization: Microsoft >>> Date: Mon, 08 Oct 2007 07:32:33 GMT >>> Subject: RE: AdRotator Problem >> >>> Hi MC, >>> >>>From your description, you're using databinding to populate the Adrotator >>> control but found that if you manually bind DataReader to it, it will >>> always miss the first record, correct? >>> >>> I've performed some test and repro this behavior. After some further >>> research, I found out the cause of the problem. It is because the >> AdRotator >>> will try dynamically inspect the datasource item's property list. It will >>> use the following code(get from reflector). >>> >>> You can see that for those datasource objects which do not support >>> "ITypedList.GetItemProperties", it will read a row(the first row) so as to >>> get all the fields(columns) info. And for datareader, this is exact the >>> case and the first row is used for getting fields info and not used at the >>> databinding later. >>> >>> private ArrayList CreateAutoGeneratedFields(IEnumerable dataSource) >>> { >>> if (dataSource == null) >>> { >>> return null; >>> } >>> ArrayList list = new ArrayList(); >>> PropertyDescriptorCollection itemProperties = null; >>> if (dataSource is ITypedList) >>> { >>> itemProperties = ((ITypedList) dataSource).GetItemProperties(new >>> PropertyDescriptor[0]); >>> } >>> if (itemProperties == null) >>> { >>> IEnumerator enumerator = dataSource.GetEnumerator(); >>> if (enumerator.MoveNext()) >>> { >>> object current = enumerator.Current; >>> if (this.IsBindableType(current.GetType())) >>> { >>> throw new >>> HttpException(SR.GetString("AdRotator_expect_records_with_advertisement_pro >> p >>> erties", new object[] { this.ID, current.GetType() })); >>> } >>> itemProperties = TypeDescriptor.GetProperties(current); >>> } >>> } >>> if ((itemProperties != null) && (itemProperties.Count > 0)) >>> { >>> foreach (PropertyDescriptor descriptor in itemProperties) >>> { >>> if (this.IsBindableType(descriptor.PropertyType)) >>> { >>> list.Add(descriptor.Name); >>> } >>> } >>> } >>> return list; >>> } >>> >>> >>> <<<<<<<<<<<<<<<<<<<<<<<<<< >>> >>> I've also found a means to resolve this. If you do not want to directly >>> return DataSet from ADO.NET query. You can manualy create a DataTable >>> object to wrapper the records(from DataReader). Here is a sample function >>> show this: >>> >>> ======================== >>> protected void BindRorator2() >>> { >>> string sql = "SELECT [id], [name], [description] FROM [itemtable]"; >>> >>> using (SqlConnection conn = new >>> SqlConnection(WebConfigurationManager.ConnectionStrings["DatabaseConnection >> S >>> tring"].ConnectionString)) >>> { >>> conn.Open(); >>> >>> using(SqlCommand comm = new SqlCommand(sql, conn)) >>> { >>> SqlDataReader reader = comm.ExecuteReader(); >>> DataTable dt = new DataTable(); >>> dt.Load(reader); >>> >>> this.AdRotator2.DataSource = dt; >>> this.AdRotator2.DataBind(); >>> >>> reader.Close(); >>> >>> } >>> >>> } >>> } >>> =============================== >>> >>> Hope this helps. >>> >>> Sincerely, >>> >>> Steven Cheng >>> >>> Microsoft MSDN Online Support Lead >>> >>> >>> >>> ================================================== >>> >>> Get notification to my posts through email? Please refer to >>> http://msdn.microsoft.com/subscripti...ault.aspx#noti >> f >>> ications. >>> >>> >>> >>> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues >>> where an initial response from the community or a Microsoft Support >>> Engineer within 1 business day is acceptable. Please note that each follow >>> up response may take approximately 2 business days as the support >>> professional working with you may need further investigation to reach the >>> most efficient resolution. The offering is not appropriate for situations >>> that require urgent, real-time or phone-based interactions or complex >>> project analysis and dump analysis issues. Issues of this nature are best >>> handled working with a dedicated Microsoft Support Engineer by contacting >>> Microsoft Customer Support Services (CSS) at >>> http://msdn.microsoft.com/subscripti...t/default.aspx. >>> >>> ================================================== >>> >>> >>> This posting is provided "AS IS" with no warranties, and confers no rights. >>> >>> >>> -------------------- >>>> From: MC <(E-Mail Removed)> >>>> Newsgroups: microsoft.public.dotnet.framework.aspnet >>>> Subject: AdRotator Problem >>>> Date: Sat, 06 Oct 2007 11:40:22 GMT >>>> I have coded an AdRotator to use a Database for it's data source. If I >>>> use a SqlDataSource control it functions as expected, however if I >>>> manually retreive the data using an OleDBDataReader It always omits the >>>> first item in the result set? Code for each solution as below. >>>> >>>> The reason I'm don't want to use the Declarative solution is that I >>>> intend to Create a custom control that inherits from AdRotator and I >>>> would then need to retrieve the Advert set programtically. >>>> >>>> Regards >>>> >>>> >>>> MC >>>> >>>> ------------------- Solution 1 - Declarative ------------------- >>>> >>>> <asp:Content ID="Content2" ContentPlaceHolderID="cphMainSite" >>>> Runat="Server"> >>>> <asp:SqlDataSource ID="SqlDataSource1" runat="server" >>>> ConnectionString="<%$ ConnectionStrings:AdsDatabase %>" >>>> ProviderName="<%$ ConnectionStrings:AdsDatabase.ProviderName %>" >>>> SelectCommand="SELECT CompanyName AS ImageUrl, CompanyName AS >>>> AlternateText, URL AS NavigateUrl, Impressions, Clicks FROM Sponsors >>>> WHERE BannerAdvert=True" /> >>>> <asp:AdRotator ID="AdRotator1" runat="server" >>>> DataSourceID="SqlDataSource1" /> >>>> </asp:Content> >>>> >>>> ------------------- Solution 2 - OleDBReader ------------------- >>>> >>>> <script runat="server"> >>>> protected void Page_Load(object sender, EventArgs e) >>>> { >>>> using (System.Data.OleDb.OleDbConnection conn = new >>>> System.Data.OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings[" >> A >>> dsDatabase"].ConnectionString)) >>>> { >>>> conn.Open(); >>>> using (System.Data.OleDb.OleDbCommand comm = new >>>> System.Data.OleDb.OleDbCommand("SELECT CompanyName AS ImageUrl, >>>> CompanyName AS AlternateText, URL AS NavigateUrl, Impressions, Clicks >>> >FROM Sponsors WHERE BannerAdvert=True", conn)) >>>> { >>>> AdRotator1.DataSource = comm.ExecuteReader(); >>>> AdRotator1.DataBind(); >>>> } >>>> } >>>> } >>>> </script> >>>> <asp:Content ID="Content2" ContentPlaceHolderID="cphMainSite" >>>> Runat="Server"> >>>> <asp:AdRotator ID="AdRotator1" runat="server" /> >>>> </asp:Content> >>>> >>> >> > |
|
||
|
||||
|
|
|
| |
![]() |
| Thread Tools | |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| AdRotator is anyone here using it? | =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | Microsoft ASP .NET | 1 | 1st Dec 2006 11:16 PM |
| adrotator? | =?Utf-8?B?RGFuaWVs?= | Microsoft ASP .NET | 0 | 26th Sep 2005 06:44 AM |
| AdRotator | Miguel Dias Moura | Microsoft ASP .NET | 1 | 14th Oct 2004 04:47 PM |
| how to use adrotator | Britney | Microsoft ASP .NET | 2 | 8th Sep 2004 09:15 PM |
| AdRotator | C Downey | Microsoft ASP .NET | 1 | 17th Jun 2004 07:26 AM |
Powered by vBulletin®. Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2010, Crawlability, Inc. |




