如何设置radiobutton值 [英] How to set radiobutton value
本文介绍了如何设置radiobutton值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在c#中创建MCQ测验应用。
管理员允许从表示层插入记录,以便如何编写radiobutton值。
我尝试过:
I want to create MCQ Quiz app in c#.
The admin allows to insert the record from presentation layer so how to write the radiobutton value .
What I have tried:
private void button5_Click(object sender, EventArgs e)
{
SqlConnection con1 = new SqlConnection("Data Source=SHINGADE-PC\\SQLEXPRESS;Initial Catalog=Quize;Integrated Security=True");
con1.Open();
SqlCommand cmd1 = new SqlCommand("insert into Question(qid,question,op1,op2,op3,op4,ans,Isimage)values ("+label2.Text+",'"+textBox1.Text+"','"radioButton1.CanSelect+"','"radioButton2.Text+"','"radioButton3.Text+"','"radioButton4.Text+"','"txtans.text+"','"txtIsimage.text+"')"), con1);
}
推荐答案
你想要类似的东西......
You want something similar to this ...
SqlConnection con1 = new SqlConnection("Data Source=SHINGADE-PC\\SQLEXPRESS;Initial Catalog=Quize;Integrated Security=True");
con1.Open();
SqlCommand cmd1 = new SqlCommand("insert into Question(qid,question,op1,op2,op3,op4,ans,Isimage)values (@lb2,@tb1,@rb1,@rb2,@rb3,@rb4,@tbtans,@tbIsImage)", con1);
cmd1.Parameters.AddWithValue("@lbl2", label2.Text);
cmd1.Parameters.AddWithValue("@tb1", TextBox1.Text);
//Assuming op1, op2, op3, op4 are bit values where 0 = False and 1 = True
cmd1.Parameters.AddWithValue("@rb1", (radioButton1.Checked) ? 1 : 0);
cmd1.Parameters.AddWithValue("@rb2", (radioButton2.Checked) ? 1 : 0);
cmd1.Parameters.AddWithValue("@rb3", (radioButton3.Checked) ? 1 : 0);
cmd1.Parameters.AddWithValue("@rb4", (radioButton4.Checked) ? 1 : 0);
cmd1.Parameters.AddWithValue(@"tbtans", txttans.Text);
cmd1.Parameters.AddWithValue(@"tbIsImage", txtIsimage.Text);
正如我在评论中所说,它取决于列op1,op2,op3和op4的类型
As I said in my comment, it rather depends on the type of the columns op1, op2, op3 and op4
这篇关于如何设置radiobutton值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文