public void Data_Vonection_2()
{
int viwee;
            TreeNode[] viwe=new TreeNode[17]{
     rootNode1,
     rootNode2,
             rootNode3,
                                             rootNode4,
     rootNode5,
     rootNode6,
     rootNode7,
     rootNode8,
     rootNode9,
     rootNode10,
     rootNode11,
     rootNode12,
     rootNode13,
     rootNode14,
     rootNode15,
     rootNode16,
     rootNode17};
 for(viwee=0;viwee<=viwe.Length;viwee++)
{
if(viwe[viwee].IsSelected)
{
custGrid.CaptionText="[ 正在清除DATAGRID所占的资源...... ]";
da.Dispose();
custGrid.CaptionText="[ 正在清除DataSe所占的资源...... ]";
ds.Dispose();
custGrid.CaptionText="[ 正在清除TABLE所占的资源...... ]";
ds.Tables.Clear();
string e="[ 正在筛选数据库里属于"+viwe[viwee].Text.ToString()+"的项目...... ]";
string wheree=viwe[viwee].Text.ToString();
custGrid.CaptionText=e;
cn=new SqlConnection("Data Source=(local);Initial Catalog=kyhard;User=sa;Password=");
da=new SqlDataAdapter("select * from 商品汇总 where 类别='"+wheree+"'",cn);
ds=new DataSet();
custGrid.CaptionText="[ 绑定数据,请稍候...... ]";
da.Fill(ds);
custGrid.CaptionText="[ 正在添加到表中...... ]";
custGrid.DataSource=ds.Tables[0];
custGrid.CaptionText=wheree;
int i=ds.Tables[0].Rows.Count;
int i_i=i-1;
statusBar1.Panels[2].Text="[共有商品数为:"+i_i.ToString()+" ]";
}
}出错提示:未处理的“System.IndexOutOfRangeException”类型的异常出现在 WindowsApplication2.exe 中。其他信息: 索引超出了数组界限。

解决方案 »

  1.   

    for(viwee=0;viwee<=viwe.Length;viwee++)
    改成
    for(viwee=0;viwee<viwe.Length;viwee++)
    即可
      

  2.   

    但是又提示:da.Fill(ds);出错!怎么办????
      

  3.   

    TreeNode[] viwe=new TreeNode[17]{...}的下标是从0开始,如果循环等于viwe.Length就算18个了!
      

  4.   

    但是又提示:da.Fill(ds);出错!怎么办????
      

  5.   

    未处理的“System.Data.SqlClient.SqlException”类型的异常出现在 system.data.dll 中。其他信息: 系统错误。
      

  6.   

    Data Source=(local);Initial Catalog=kyhard;User=sa;Password=
    _________
    把(local)改成计算机名称看看!
      

  7.   

    还有把 Password=" 的''去掉,不要了,直接Password=就可以了!
      

  8.   

    本来就没有了的啊!
    因为前面有个",所以再要个"来和它交配,不然回erroing!!!!
      

  9.   

    我怀疑是:
    string wheree=viwe[viwee].Text.ToString();
    这句的问题!
      

  10.   

    你指定一个存在的类别,不要wheree看看!
      

  11.   

    if(rootNode1.IsSelected)
    {
                custGrid.CaptionText="[ 正在清除DATAGRID所占的资源...... ]";
                da.Dispose();
       custGrid.CaptionText="[ 正在清除DataSe所占的资源...... ]";
       ds.Dispose();
                custGrid.CaptionText="[ 正在清除TABLE所占的资源...... ]";
       ds.Tables.Clear();
       string e="[ 正在筛选数据库里属于"+rootNode1.Text.ToString()+"的项目...... ]";
    string wheree=rootNode1.Text.ToString();
    custGrid.CaptionText=e;
    cn=new SqlConnection("Data Source=(local);InitialCatalog=kyhard;User=sa;Password=");
    da=new SqlDataAdapter("select * from 商品汇总 where 类别='"+wheree+"'",cn);
    ds=new DataSet();
    custGrid.CaptionText="[ 绑定数据,请稍候...... ]";
    da.Fill(ds);
    custGrid.CaptionText="[ 正在添加到表中...... ]";
    custGrid.DataSource=ds.Tables[0];
                    custGrid.CaptionText=wheree;
    int i=ds.Tables[0].Rows.Count;
    int i_i=i-1;
    statusBar1.Panels[2].Text="[共有商品数为:"+i_i.ToString()+" ]";
    }这段代码就可以!!!!!
    但是要重复17次,冗余过多!!!!
      

  12.   

    去掉  [where 类别='"+wheree+"']就可以,我想wheree是没有值的,但是那段代码又怎么解释呢?
      

  13.   

    select * from 商品汇总 where 类别='办公类'
    如果存在“办公类”这样的类别也会出错?