このデータグリッドをバインドしようとすると苦労しています。コードを実行するたびに、「リーダーが閉じたときにReadを呼び出す試みが無効です」というエラーメッセージが表示されます。私はどこの読者を閉じているのかわかりません。手伝ってくれませんか?データグリッドをロードするための私のコードは以下の通りです:リーダーが閉じられているときに読み込みを呼び出す試みが無効です
protected void LoadGrid()
{
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager.ConnectionStrings["VTC"].ConnectionString;
conn.Open();
string sql = "select * from roi_tracking";
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
using (SqlDataReader sqlReader = cmd.ExecuteReader())
{
gridROI.DataSource = sqlReader;
gridROI.DataBind();
sqlReader.Dispose();
cmd.Dispose();
}
}
}
}
あなたのusingステートメントは、このスレッドをチェックするために接続を閉じるでしょう、あなたの質問に答えるかもしれないhttp://stackoverflow.com/questions/5516914/invalid-attempt-to-read-when-reader-is-closed –
同じ別のシナリオでのエラーhttp://stackoverflow.com/questions/6775136/invalid-attempt-to-call-read-when-reader-is-closed-error-for-lengthy-operatio – Lijo