标题:索引超出范围。必须为非负值并小于集合大小(超紧急,求救!!!)
只看楼主
贝蕾
Rank: 1
等 级:新手上路
帖 子:62
专家分:0
注 册:2008-6-26
得分:0 
确切的说就是sql语句有拼写错误,好好检查之后再发帖……
2008-06-30 13:39
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
得分:0 
Response.Write(sdr["UF_CARD_TITLE"]);
如果用输出的方法内容全可以读出来

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-06-30 13:47
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
得分:0 
protected void binddingzhi()
    {
        
        string sqlcomm = "";
        sqlcomm += "SELECT UF_CARD_TITLE,UF_CARD_USERID,UF_CARD_ADDTIME,UF_RECARD_SORT,";
        sqlcomm += "UF_CARD_VISITQUANTITY,UF_RECARD_ADDTIME,UF_RECARD_USERID FROM UF_CARD,UF_RECARD WHERE UF_RECARD_SORT IN";
        sqlcomm += " (SELECT count(*) FROM UF_RECARD WHERE UF_RECARD_CARDID IN (SELECT UF_CARD_ID FROM UF_CARD))";
        sqlcomm += " AND UF_CARD_TOP = 1 ORDER BY UF_CARD_ADDTIME desc";
        SqlConnection myconn = new SqlConnection(publicclass.getconnstr());
        myconn.Open();
        SqlCommand mycommand = new SqlCommand(sqlcomm, myconn);
        SqlDataReader sdr = mycommand.ExecuteReader();
        for (int i = 0; i < 10; i++)
        {
            if (sdr.Read())
            {
                Response.Write(sdr["UF_CARD_TITLE"]);
                Response.Write("<br>");
                Response.Write(sdr["UF_CARD_USERID"]);
                Response.Write("<br>");
                Response.Write(sdr["UF_CARD_ADDTIME"]);
                Response.Write("<br>");
                Response.Write(sdr["UF_RECARD_SORT"]);
                Response.Write("<br>");
                Response.Write(sdr["UF_CARD_VISITQUANTITY"]);
                Response.Write("<br>");
                Response.Write(sdr["UF_RECARD_USERID"]);
                Response.Write("<br>");
                Response.Write(sdr["UF_RECARD_ADDTIME"]);
                Response.Write("<br>");
                //((LinkButton)(GridView1.Rows[0].Cells[1].FindControl("LinkButton1"))).Text = sdr["UF_CARD_TITLE"].ToString();
                //((Label)(GridView1.Rows[0].Cells[2].FindControl("Label2"))).Text = sdr["UF_CARD_USERID"].ToString();
                //((Label)(GridView1.Rows[0].Cells[2].FindControl("Label3"))).Text = sdr["UF_CARD_ADDTIME"].ToString();
                //((Label)(GridView1.Rows[0].Cells[3].FindControl("Label4"))).Text = sdr["UF_RECARD_SORT"].ToString();
                //((Label)(GridView1.Rows[0].Cells[3].FindControl("Label5"))).Text = sdr["UF_CARD_VISITQUANTITY"].ToString();
                //((Label)(GridView1.Rows[0].Cells[4].FindControl("Label6"))).Text = sdr["UF_RECARD_USERID"].ToString();
                //((Label)(GridView1.Rows[0].Cells[4].FindControl("Label7"))).Text = sdr["UF_RECARD_ADDTIME"].ToString();            
            }
            else
            {
                Response.Write("no");
            }
        }
    }

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-06-30 13:49
tomtory
Rank: 1
来 自:重庆
等 级:新手上路
帖 子:705
专家分:0
注 册:2008-6-12
得分:0 
Response.Write(sdr["UF_RECARD_ADDTIME"]);
你这样得到了值 那么证明sdr["UF_RECARD_ADDTIME"]是将值取出来了的

报的是索引超出范围

应该是
((Label)(GridView1.Rows[0].Cells[2].FindControl("Label2"))).Text
这个没有找到Label控件
2008-06-30 17:18
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
得分:0 
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BorderColor="#8080FF"
        Width="100%">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <img src="images/bbs_1_12.jpg" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="顶置">
                <ItemTemplate>
                    &nbsp;<asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>
                    <img src="images/new.gif" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="作者">
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br />
                    <asp:Label ID="Label3" runat="server" ForeColor="DarkGray" Text="Label"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="回复/查看">
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" ForeColor="DarkGreen" Text="Label"></asp:Label>
                    /<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="最后发表">
                <ItemTemplate>
                    <asp:Label ID="Label6" runat="server" Text="Label"></asp:Label>
                    <br />
                    <span style="color: darkgray">by</span>
                    <asp:Label ID="Label7" runat="server" ForeColor="Silver" Text="Label"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <HeaderStyle BackColor="MediumTurquoise" Height="30px" />
    </asp:GridView>

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-06-30 18:15
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
得分:0 
怎么可能没有label啊

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-06-30 18:16
tomtory
Rank: 1
来 自:重庆
等 级:新手上路
帖 子:705
专家分:0
注 册:2008-6-12
得分:0 
不是说没有label,而是说label没有找到

你打断点监视一下看看的嘛

这样你可以找到详细的错误位置噻
2008-07-01 09:21



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-221700-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.334212 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved