不知道大家 有沒有遇到過這樣的問題,前台頁用Repeater循環顯示資料,背景用SqlDataReader來讀取資料時,資料庫中的記錄的第一條顯示不出來,下面就是我寫的一個,在其中加入了一個判斷,在頁面上顯示時不顯示第一條記錄,剛開始以為是被上層覆寫了,調整層的間距也沒有顯示出來。
public void bindChengji()
{
string sql = "select * from geren";
conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
SqlDataReader sdr = cmd.ExecuteReader();
if(sdr.Read())
{
grchengji.DataSource = sdr;
grchengji.DataBind();
}
cmd.Dispose();
conn.Close();
}
在經過幾經周折後,試着把判斷語句給删掉,反而出現了第一條記錄。
public void bindChengji()
{
string sql = "select * from geren";
conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
SqlDataReader sdr = cmd.ExecuteReader();
grchengji.DataSource = sdr;
grchengji.DataBind();
cmd.Dispose();
conn.Close();
}
不知道這是怎麼回事,請各位大哥大姐能給小弟開闊一下知識面,幫小弟解開心中這個謎。