string connstr="workstation id=RAND2;packet size=4096;user id=sa;data source=RAND2;persist security info=False;initial catalog=C";
string findstr="select * from person where [name]='"+ txtSerch.Text +"'";
SqlConnection conn;
conn=new SqlConnection(connstr);
conn.Open(); SqlCommand cmd;
cmd=new SqlCommand (findstr,conn);
SqlDataReader myReader;
myReader=cmd.ExecuteReader ();问题是:
myReader.Read()之后,能不能像ADO.recordset那样有一个ado.recordset.recordset 属性,取得当前记录集里记录的条数?之
string findstr="select * from person where [name]='"+ txtSerch.Text +"'";
SqlConnection conn;
conn=new SqlConnection(connstr);
conn.Open(); SqlCommand cmd;
cmd=new SqlCommand (findstr,conn);
SqlDataReader myReader;
myReader=cmd.ExecuteReader ();问题是:
myReader.Read()之后,能不能像ADO.recordset那样有一个ado.recordset.recordset 属性,取得当前记录集里记录的条数?之
dataset.tables[0].rows.count
dataset是用dataadpater的fill填充的
具体语法参见msdn
用下面的while结构能把我查询到的记录一条条显示出来,但是共有多少条记录我不用管.
但如果改为for 结构呢?我一定要知道循环的终值才行,这个终值就是记录的条数,条数真的无法取得吗?
while(myReader.Read())
{
console.writeline (myReader[0].tostring());
}
while(myReader.Read())
{
console.writeline (myReader[0].tostring());
i++;
}
最后i就是行数
谢谢各位, 以后用DATASET
取记录数没有直接的办法,ado也只有在使用 客户端游标 或者 服务器端游标并调用MoveLast后才能取得记录数