我正在使用嵌套中繼器。我的問題似乎是在目前,當我執行我的SQL命令,沒有數據返回給數據讀取器。即使我運行完全相同的查詢(複製並粘貼)到SQL Server中。SQL命令未填充數據讀取器
我的noteDrClient閱讀器不包含數據,但它確實知道表中有5列。我不知道現在要做什麼或者爲什麼沒有數據傳入數據讀取器。任何人都可以看到明顯的問題?
SqlConnection con = new SqlConnection("Data Source=***;Initial Catalog=*;User ID=*;Password=*;Integrated Security=False;MultipleActiveResultSets=true;");
上面是我的連接字符串。請注意,我將多個活動結果集設置爲true。我這樣做是因爲我的數據閱讀器一直處於打開狀態,儘管它已關閉。
protected void rptList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
RepeaterItem item = e.Item;
if ((item.ItemType == ListItemType.Item) ||
(item.ItemType == ListItemType.AlternatingItem))
{
System.Data.Common.DbDataRecord rd = (System.Data.Common.DbDataRecord)e.Item.DataItem;
Repeater nestedRepeater = e.Item.FindControl("NotesRepeater") as Repeater;
string FID = rd[0].ToString();
using (cmd2 = new SqlCommand("SELECT * FROM notes WHERE FID = 1356;", con)) ;
SqlDataReader noteDrClient = cmd2.ExecuteReader(); //no data is being filled to the data reader... even though this command pulls data in SQL Server Management Studio.
if (noteDrClient.Read()) { //bind the repeater if there is data to bind
nestedRepeater.DataSource = noteDrClient;
nestedRepeater.DataBind();
}
noteDrClient.Close();
}
您在Management Studio中的同一個用戶在連接字符串中配置的用戶登錄? – Jupaol
是的,相同的用戶名。 –
http://msdn.microsoft.com/en-us/library/h32h3abf%28v=vs.80%29.aspx –