循环读取数据的疑问
SqlDataAdapter sdr=new SqlDataAdapter();
sdr.SelectCommand=new SqlCommand( "select top 10 * from UserPhoto order by pid desc ",conn);
DataSet ds= new DataSet();
sdr.Fill(ds, "emp ");
for(int i=0;i <=ds.Tables[0].Rows.Count;i++)
{
a = "sPicArr[ "+i+ "] = new Array( 'UserPhoto/ "+ds.Tables[ "emp "].Rows[0][ "PhotoImg "].ToString()+ " '); ";
}
Response.Write(a);
我想读出前十条记录
现在数据库中只有四条记录
循环读出来的结果却是第一条,一共四条一样的
a = "sPicArr[ "+i+ "] = new Array( 'UserPhoto/ "+ds.Tables[ "emp "].Rows[i][ "PhotoImg "].ToString()+ " '); ";
可是这样读的话,就会出错!
提示:在位置 4 处没有任何行
也是就是我改的那部分出错
请各位大哥帮帮忙
------解决方案--------------------for(int i=0;i <ds.Tables[0].Rows.Count;i++)
{
a = "sPicArr[ "+i+ "] = new Array( 'UserPhoto/ "+ds.Tables[ "emp "].Rows[i][ "PhotoImg "].ToString()+ " '); ";
}