AdRotator Problem

Discussion in 'ASP .Net' started by MC, Oct 6, 2007.

  1. MC

    MC Guest

    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["AdsDatabase"].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, Oct 6, 2007
    #1
    1. Advertising

  2. 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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.

    ==================================================


    This posting is provided "AS IS" with no warranties, and confers no rights.


    --------------------
    >From: MC <>
    >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], Oct 8, 2007
    #2
    1. Advertising

  3. 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: (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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
    >
    >==================================================
    >
    >
    >This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >
    >--------------------
    >>From: MC <>
    >>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], Oct 10, 2007
    #3
  4. MC

    MC Guest

    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: (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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
    >>
    >> ==================================================
    >>
    >>
    >> This posting is provided "AS IS" with no warranties, and confers no rights.
    >>
    >>
    >> --------------------
    >>> From: MC <>
    >>> 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, Oct 11, 2007
    #4
  5. 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 <>
    >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: (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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
    >>>
    >>> ==================================================
    >>>
    >>>
    >>> This posting is provided "AS IS" with no warranties, and confers no

    rights.
    >>>
    >>>
    >>> --------------------
    >>>> From: MC <>
    >>>> 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], Oct 12, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DDK

    Adrotator and flash banner?

    DDK, Jun 25, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    3,316
    akino
    Oct 25, 2007
  2. C Downey

    AdRotator

    C Downey, Jun 16, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    401
    Trevor Benedict R
    Jun 17, 2004
  3. Britney

    how to use adrotator

    Britney, Sep 8, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,977
    Rutger Smit
    Sep 8, 2004
  4. John Buchmann

    Similar to adrotator, but to generate text?

    John Buchmann, Sep 21, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    369
    Hermit Dave
    Sep 25, 2004
  5. Randy

    AdRotator multiple on same page problem

    Randy, Jun 19, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    136
    Randy
    Jun 19, 2004
Loading...

Share This Page