这个循环语句有什么错误吗???为什么每次只能选出两条记录????
---------------------------------------------------------------------------------------
string connection = ConfigurationSettings.AppSettings["GetConncetion"].ToString();
string extno1 = ConfigurationSettings.AppSettings["extno1"].ToString();
string uid = ConfigurationSettings.AppSettings["uid"].ToString();
string pswd = ConfigurationSettings.AppSettings["pswd"].ToString();
SqlConnection myconnection = new SqlConnection(connection); 
myconnection.Open(); 
string selectstring = "select  top 5 * from TSMS "; 
SqlDataAdapter mycommand = new SqlDataAdapter(selectstring, myconnection);
DataTable dt = new DataTable();
mycommand.Fill(dt);
HttpWebResponse res = null;
foreach(DataRow dr in dt.Rows)
 {
           string strmsg = System.Web.HttpUtility.UrlEncode((string)dr["Content"],System.Text.Encoding.GetEncoding("GB2312"));
            string strmob = (string)dr["MobileNum"];
            string strUrl = "http://econnect.hotdotchina.com/econnect/pitf/submit.jsp?uid=" + uid + "&pswd=" + pswd + "&extno=" + extno1 + "&msg=" + strmsg + "&mob=" + strmob;
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strUrl);
            res = (HttpWebResponse)req.GetResponse ();
}

解决方案 »

  1.   

    是不是表里只有两条数据  TOP5就只能取2条了
      

  2.   

    foreach(DataRow dr in dt.Rows)
    DataRow我怎么记得是不支持foreach的?我记得他好象没有实现XX接口所以不支持foreach.你可以改成
    for(int i=0;i<dt.Rows.Count;i++)
    {
        把DataRow替换成dt.Rows[i]
    }再调试试试,这个可是货真价实的循环5次.
      

  3.   

    你可以改成
    for(int i=0;i<dt.Rows.Count;i++)
    {
        把DataRow替换成dt.Rows[i]
    }再调试试试,这个可是货真价实的循环5次.
    ----------------------------------------------------
    不行呀,还是只能选出两条记录????
      

  4.   

    foreach(DataRow dr in dt.Rows)
    这里没有错,建议看看
    dt.Rows.Count的值
      

  5.   

    foreach会枚举你所有dt.rows, 除非你选出来的dt.rows的数据只有两条,你可以跟踪下dt.rows.count到底等于几.
      

  6.   

    同意 Firestone2003(笨笨小猪) ( ) 信誉:98  2006-05-31 15:10:00  得分: 0  
     
    只有两条记录