datareader返回纪录条数问题
public static int count(string name)
{
SqlConnection con=DB.createcon();
con.Open();
SqlCommand cmd=new SqlCommand( "select * from answer where name= ' "+name+ " ' ",con);
SqlDataReader sdr=cmd.ExecuteReader();
int RecordCount = 0;
if(sdr.Read())
{
RecordCount++;
}
return RecordCount;
}
lable.text=count(name);
为啥计算出来的数据条数总是一呢?
数据库满足条件的纪录不止一条
------解决方案--------------------while(sdr.Read())
{
RecordCount++;
}