从db取值到rb [英] fetching the value from the db to rb

查看:130
本文介绍了从db取值到rb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在做在线apti测试项目.但是可能是,当我从数据库中获取数据时,然后单击下一步按钮时,它将恢复正常运行,并且将以相同的选项回答相同的问题.朋友,您能如何帮助我,当我单击下一步按钮时,如何从数据库获取问题.请紧迫
代码:-


i have doing online apti test proj . but prob is that when i m fetching the data frm the db then it will ok bt after that when i m clicking on next button it will reply the same question with same option . friends can u help me how can i fetch the question from db when i m click in next button. plz its urgent
code:--

public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=major;Integrated Security=True");
    int i;
    protected void Page_Load(object sender, EventArgs e)
    {
        //if( Page.IsPostBack = false)
        //{
        SqlDataAdapter da = new SqlDataAdapter("select* from exam", con);
        DataTable dt = new DataTable();
        da.Fill(dt);
        for (i = 0; i < dt.Rows.Count; i++)
        {
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("select * from exam", con);
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    Label3.Text = dr[0].ToString();
                    RadioButton1.Text = dr[1].ToString();
                    RadioButton2.Text = dr[2].ToString();
                    RadioButton3.Text = dr[3].ToString();
                    RadioButton4.Text = dr[4].ToString();
                                    }
                //cmd.ExecuteNonQuery();
                //con.Close();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }

            con.Close();
        }
          
        string s = i.ToString();
        Session["s"] = s;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("result.aspx");
    }

    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {

        RadioButton1.BackColor = System.Drawing.Color.Red;
        RadioButton1.ForeColor = System.Drawing.Color.Blue;
       RadioButton2.BackColor = System.Drawing.Color.Red;
        RadioButton2.ForeColor = System.Drawing.Color.Blue;
        }

    protected void LinkButton73_Click(object sender, EventArgs e)
    {

        Response.Redirect("xam.aspx");

    }
}

推荐答案

你好

您无需传递两个不同的查询

您可以使用

Hello

You need not to pass two different queries

you can use

SELECT Top 1 * FROM MasterQual ORDER BY Rand((1000 * TransId) * DatePart(millisecond,GetDate())) // here 1000 is used for chances of repetition of a question to increase chance use lesser no.



在您的第一个查询中,并借助该dt,您可以将值分配给标签和单选按钮



in your first query and with the help of that dt you can assign values to label and radiobuttons


这篇关于从db取值到rb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆