//取得相应日期对应测点名称下的沉陷值
    public static ArrayList GetCXZ()
    {
        ArrayList arrayList_GCRQ = GetGCRQ();
        ArrayList arrayList_CDMC = GetCDMC();
        ArrayList arrayList_CXZ = null;        SqlConnection con = new SqlConnection();
        con.ConnectionString = conString;
        con.Open();        string[,] strSQL = new string[arrayList_GCRQ.Count,arrayList_CDMC.Count];
        SqlCommand cmd = null;
        SqlDataReader data = null;
  
        for (int i = 0; i < arrayList_GCRQ.Count; i++)  
        {
            for (int j = 0; j < arrayList_CDMC.Count; j++)
            {
                strSQL[i][j] = "select CXZ from BTCZWY_LR,BMSXWY_KZ where CDBH=BH_BMSXKZ and GCRQ= "+arrayList_GCRQ[i]+" and CDMC_BMSXKZ='" + arrayList_CDMC[j].ToString().Trim()+"'";
                cmd = new SqlCommand(strSQL[i][j], con);
                data = cmd.ExecuteReader();
                while (data.Read())
                {
                    arrayList_CXZ.Add(data.GetValue(0).ToString());
                }
                data.Close();
            }
        }
        return arrayList_CXZ;
    }编译报错如下:
编译错误 
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: CS0022: [] 内索引数错误,应为“2”源错误:
行 103:            for (int j = 0; j < arrayList_CDMC.Count; j++)
行 104:            {
行 105:                strSQL[i][j] = "select CXZ from BTCZWY_LR,BMSXWY_KZ where CDBH=BH_BMSXKZ and GCRQ= "+arrayList_GCRQ[i]+" and CDMC_BMSXKZ='" + arrayList_CDMC[j].ToString().Trim()+"'";
行 106:                cmd = new SqlCommand(strSQL[i][j], con);
行 107:                data = cmd.ExecuteReader();源文件: d:\My Documents\Visual Studio 2005\WebSites\StatisticQuery\渗流监测\SXWY.aspx.cs    行: 105
看看如何修改?

解决方案 »

  1.   

    将改成这样也是不行的:strSQL[i][j] ==》strSQL[i,j] ,还是报同样的错误!
      

  2.   

    改成:
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < arrayList_GCRQ.Count; i++)  
            { 
                for (int j = 0; j < arrayList_CDMC.Count; j++) 
                { 
                    sb.Append("select CXZ from BTCZWY_LR,BMSXWY_KZ where CDBH=BH_BMSXKZ and GCRQ= "+arrayList_GCRQ[i]+" and CDMC_BMSXKZ='" + arrayList_CDMC[j].ToString().Trim()+"'\n"); 
                } 
            } cmd = new SqlCommand(sb.ToString(),con); 
                    data = cmd.ExecuteReader(); 
                    while (data.Read()) 
                    { 
                        arrayList_CXZ.Add(data.GetValue(0).ToString()); 
                    } 
                    data.Close(); :尽量不要在循环里面搞这种事情
      

  3.   

    噢,上面写错了,把arrayList_CDMC[j].ToString().Trim()+"'\n"); 
    改成 arrayList_CDMC[j].ToString().Trim()+"' \n union all "); 
    拼接好了之后呢把最后一个“union all”字符去掉一次性读出所有数据会更好使