0

テーブルから次のレコードを取得して、として表示したいQuestion。以下のコードではQuestion、テーブルから次を取得できません。

protected void Page_Load(object sender, EventArgs e)
{
    if (Page.IsPostBack == false)
    {
        Quiz_Load();

    }
}
private void Quiz_Load()
{
    try
    {
        if (Session["UserQuizID"] != null)
        {
            string mayank = "mm.bhagat";
            string UserQuiz_ID = Session["UserQuizID"].ToString();
            SqlConnection con = new SqlConnection(c);
            SqlCommand cmd = new SqlCommand("select top 0.1 percent QuestionID, Title, Answer1,Answer2,Answer3,Answer4,UserAnswer from [Table_UserAnswer] WHERE UserQuizID = '" + UserQuiz_ID.ToString() + "' AND UserName = '" + mayank.ToString() + "' order by newid()", con);
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                Session["QuestionID"] = dr[0].ToString();
                Lbl_QuestionTitle.Text = dr[1].ToString();
                RadBut_Answer.Items.Add(dr[2].ToString());
                RadBut_Answer.Items.Add(dr[3].ToString());
                RadBut_Answer.Items.Add(dr[4].ToString());
                RadBut_Answer.Items.Add(dr[5].ToString());
                Session["UserAnswer"] = dr[6].ToString();                   
            }
            else
            {

            }

            con.Close();
        }
        else
        {
            Response.Redirect("Start.aspx");
        }

    }
    catch
    {

    }        
}
protected void RadBut_Answer_SelectedIndexChanged(object sender, EventArgs e)
{
    try
    {
        int getvalue;
        getvalue = Convert.ToInt32(RadBut_Answer.SelectedIndex + 1);
        Lbl_SelectedAnsMsg.Text = MessageFormatter.GetFormattedAlertsMessage("Your Selected Answer is : " + getvalue.ToString());
        Session["UserAnswer"] = getvalue.ToString();
    }
    catch
    { 
    }
}

protected void But_Next_Click(object sender, EventArgs e)
{
    UpdateUserAns();
    if (Session["UserAnswer"] == null)
    {
        Response.Redirect("Result.aspx");
    }
    else
    {

    }
}

private void UpdateUserAns()
{
    try
    {
        string mayank = "mm.bhagat";
        string UserQuiz_ID = Session["UserQuizID"].ToString();
        string Question_ID = Session["QuestionID"].ToString();
        string User_Answer = Session["UserAnswer"].ToString();
        SqlConnection con = new SqlConnection(c);
        SqlCommand cmd = new SqlCommand("UPDATE Table_UserAnswer SET UserAnswer='" + User_Answer.ToString() + "' WHERE UserQuizID = '"+ UserQuiz_ID.ToString() +"' AND QuestionID = '"+Question_ID.ToString()+"' AND UserName = '"+mayank.ToString()+"'", con); 
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
        cmd.Cancel();
    }
    catch
    {

    }
}
4

1 に答える 1

1

こんにちは、この投稿クライアントをここで確認してください

ここであなたの質問の解決策を見つけることができます

于 2013-02-22T11:06:52.577 に答える