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 中。其他信息: 索引超出了数组界限。
{
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 中。其他信息: 索引超出了数组界限。
改成
for(viwee=0;viwee<viwe.Length;viwee++)
即可
_________
把(local)改成计算机名称看看!
因为前面有个",所以再要个"来和它交配,不然回erroing!!!!
string wheree=viwe[viwee].Text.ToString();
这句的问题!
{
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次,冗余过多!!!!
如果存在“办公类”这样的类别也会出错?