0

私のaspxページには、DetailsViewとSqlDataSource、および「次へ」というラベルの付いたボタンがあります。前に進むだけでよいので、データソース モードは DataReader に設定されています。

私のcsページには、次のものがあります。

    protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        string connectionString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
        conn = new SqlConnection(connectionString);
        comm = new SqlCommand("PickRandomQuestions", conn);
        comm.CommandType = System.Data.CommandType.StoredProcedure;
        comm.Parameters.Add("QuizID", SqlDbType.Int);
        comm.Parameters["QuizID"].Value = 1;
        conn.Open();
        reader = comm.ExecuteReader();
        QuestionDetails.DataSource = reader;
        QuestionDetails.DataBind();
    }
}
protected void ButtonNext_Click(object sender, EventArgs e)
{
    if (reader.Read())
    {
        QuestionDetails.DataSource = reader;
        QuestionDetails.DataBind();
    }
    else
    {
        conn.Close();
        reader.Close();
    }
}

[次へ] ボタンをクリックすると、System.NullReferenceException: オブジェクト参照がオブジェクトのインスタンスに設定されていません。

私は何を間違っていますか?

4

0 に答える 0