我正在使用asp.net中的在线测试应用程序而且我在将已检查的答案状态保存回数据库时遇到了麻烦,即一旦我点击我的aspx页面中的下一个按钮就会发生这两件事
1)它应捕获当前检查的选项,并将该特定选项的值作为true添加到我的数据库IS_Marked列中。
2)它还应该提出下一组问题和选项
后者很好,但我没有得到任何关于如何将检查答案保存回数据库的线索
我的aspx有4个复选框
我的下一个按钮点击事件如下,
protected void BtnNext_Click(object sender,EventArgs e)
{
if(qid == maxid)//检查当前的que id是否等于DB中的last que id
{
BtnNext.Enabled = false; //if its last que then next button is disabled
}
else
{
BtnPrevious.Enabled = true; // if not last question next button is enabled
QuestionSet q = new QuestionSet(); //Question set is an entity to hold que text and options list
StudentB b = new StudentB(); //object of my business class
q = b.GetQuestion(1, 1, qid, 'N', 0);//passing student id, test id, question id, action taken, i.e button clicked(prev, next, last, first) and selected question(i.e any question that is present)
qid = Convert.ToInt32(q.Question_Id);
LblQStn.Text = q.Question_Text;
CheckBox1.Text = q.Options[0].Option_Text;//talking to business and model layer and getting que and ans from database and giving to checkboxes
CheckBox2.Text = q.Options[1].Option_Text;
CheckBox3.Text = q.Options[2].Option_Text;
CheckBox4.Text = q.Options[3].Option_Text;
}
}
现在当他检查任何答案时,我需要将其状态保存到数据库中 任何解决方案都非常感谢,
提前致谢
答案 0 :(得分:0)
首先,您需要设置与数据库的连接。例: // sqlString是你的连接字符串//
dbconn = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("sqlString"))
dbconn.Open()
strsql = "INSERT INTO IS_Marked ([Mark]) VALUES ('" + Bedrijf + "')"
dbcomm = New SqlCommand(strsql, dbconn)
dbcomm.ExecuteNonQuery()
dbconn.Close()
这将是您的基本sql命令。
正如你所看到的那样([你的价值])我们接下来会做什么。
Dim dbconn As SqlConnection
Dim dbcomm As SqlCommand
Dim strsql, Checked_Mark As String
Mark = YourCheckBox.CheckedValue
所以你的最终结果将是这样的:
Dim dbconn As SqlConnection
Dim dbcomm As SqlCommand
Dim strsql, Mark As String
Mark = YourCheckBox.CheckedValue
dbconn = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("sqlString"))
dbconn.Open()
strsql = "INSERT INTO IS_Marked ([Mark]) VALUES ('" + Bedrijf + "')"
dbcomm = New SqlCommand(strsql, dbconn)
dbcomm.ExecuteNonQuery()
dbconn.Close()