一个数据源总有多条数据,怎样只显示其中3条?
DataTable dt3;
string TextSql3 = String.Format( "select * from roomnum where serverno=1 order by roomno ");
dt3 = Database.ExecuteDataset(System.Data.CommandType.Text, TextSql3).Tables[0];
foreach (DataRow dr3 in dt3.Rows)
{
}
不能改sql语句,最好能把每条数据的值付给不同的变量
------解决方案--------------------DataTable dt3;
string TextSql3 = "select * from roomnum where serverno=1 order by roomno ";
dt3 = Database.ExecuteDataset(System.Data.CommandType.Text, TextSql3).Tables[0];
for(int i=;i <dt3.Rows.Count&&i <3;i++)
{
string c1= dt3.rows[i][列名].ToString();
string c2= dt3.rows[i][列名].ToString();
.............
}
------解决方案--------------------生成一个随机数(0到记录数之间的任一整数)i
string c1= dt3.rows[i][列名].ToString();