您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> .NET >> 大学生修改程序猝死 新手求助修改程序

大学生修改程序猝死 新手求助修改程序

来源:网络整理     时间:2016/8/12 9:45:18     关键词:大学生修改程序猝死

关于网友提出的“大学生修改程序猝死 新手求助修改程序”问题疑问,本网通过在网上对“大学生修改程序猝死 新手求助修改程序”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题:大学生修改程序猝死 新手求助修改程序
描述:

   protected void Page_Load(object sender, EventArgs e)
    {
        string voteID = "1";
        SqlConnection con = voteDB.createConnection();
        con.Open();
        SqlCommand cmdItem = new SqlCommand("select voteItem,voteNum from t_voteDetails where voteID="+voteID, con);
        SqlDataReader sdr = cmdItem.ExecuteReader();
      
        sdr.Read();
        string strItem = sdr["voteItem"].ToString();
        //string strItem = Convert.ToString(sdr.GetString(0));
        string[] arrItem = strItem.Split('|');

        sdr.Close();
     
        SqlCommand cmdSum = new SqlCommand("select sum(voteNum) from t_voteDetails where voteId=" + voteID, con);
        decimal sumAll = Convert.ToDecimal(cmdSum.ExecuteScalar());
        Response.Write(sumAll+".....");
       
        SqlDataReader dr = cmdItem.ExecuteReader();
      
        Response.Write("");
        foreach (string s in arrItem)
        {
            
            string item = s.Split(',')[0].ToString();
            decimal percent = 0;
            int num=0;
            string strPercent;
            while (dr.Read())
            {
                 num = dr.GetInt32(1);
            
                 percent = (num / sumAll) * 100;
                 decimal p = percent * 1000 / 10;
                 if (p > 4) { percent += (decimal)0.01; }
                strPercent= percent.ToString();
                if (strPercent.Length>5) { strPercent=strPercent.Substring(0, 5); }
            Response.Write("" + item + "" + num + "票"+strPercent+"%");
           
            }
        }
        dr.Close();
        Response.Write("");
    
       
        con.Close();
    }
红色部分应该如何修改!!!使得voteItem多条数据都能加入数组arrItem中..??


解决方案1:


 List  strItem =new List ();  
while(sdr.Read()) 
    strItem.add(sdr["voteItem"].ToString());  
         } 
string[] arrayItem = strItem.ToArray();//转换为数组

解决方案2:

     List strItem =new List(); 
while(sdr.Read())
    strItem.add(sdr["voteItem"].ToString()); 
         }
这样也不用你去split


以上介绍了“大学生修改程序猝死 新手求助修改程序”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3222469.html

大学生修改程序猝死相关图片

大学生修改程序猝死相关文章