以下是引用片段: 其关键代码实现如下: Public Sub UpdateList() '设置表格的标头和样式 '动态从数据库中装载数据 '1 Dim arrName() arrName = Array("编号", "题目内容", "答案A", "答案B", "答案C", "答案D", "正确答案") Dim arrColwidth() arrColwidth = Array(0, ddd.Width / 6, ddd.Width / 6, ddd.Width / 6, ddd.Width / 6, ddd.Width / 6, ddd.Width / 6 - 300) ddd.Cols = 7 ddd.Rows = 2 Dim i As Long For i = 0 To ddd.Cols - 1 ddd.ColWidth(i) = arrColwidth(i) ddd.TextMatrix(0, i) = arrName(i) ddd.TextMatrix(1, i) = "" Next ddd.Rows = 28 Call UpdateDDD(ddd, ExecSql("SELECT ID, Title, AnswerA, AnswerB, AnswerC, AnswerD, Answer FROM dbo.SingleProblem"), 1) End Sub Private Sub btnDel_Click() '删除单选题 Call Exec_SqL("delete SingleProblem where id=" & idkey & " ") Unload Me End Sub Private Sub btnSave_Click() Dim strSelect As String Dim i As Long For i = 0 To 3 If Me.Option1(i).Value = True Then strSelect = Me.Option1(i).Caption End If Next If idkey > 0 Then '修改单选题 Call Exec_SqL("update SingleProblem set title='" & Me.txtTmnr.Text & "',AnswerA='" & Me.Text1.Text & "',AnswerB ='" & Me.Text2.Text & "',Answerc='" & Me.Text3.Text & "',AnswerD='" & Me.Text4.Text & "',Answer='" & strSelect & "' where id=" & idkey & " ") Else '添加单选题 Call Exec_SqL("insert into SingleProblem values('" & Me.txtTmnr.Text & "','" & Me.Text1.Text & "','" & Me.Text2.Text & "','" & Me.Text3.Text & "','" & Me.Text4.Text & "','" & strSelect & "')") End If Unload Me End Sub Private Sub Form_Load() '显示当选题信息内容 Me.btnDel.Enabled = False If idkey > 0 Then Dim tmprs As New ADODB.Recordset Set tmprs = ExecSql("select * from SingleProblem where id=" & idkey & "") With tmprs If .RecordCount > 0 Then Me.txtTmnr.Text = .Fields("Title").Value Me.Text1.Text = .Fields("AnswerA").Value Me.Text2.Text = .Fields("AnswerB").Value Me.Text3.Text = .Fields("AnswerC").Value Me.Text4.Text = .Fields("AnswerD").Value Dim i As Long For i = 0 To 3 If Me.Option1(i).Caption = .Fields("Answer").Value Then Me.Option1(i).Value = True End If Next Me.btnDel.Enabled = True End If End With End If If boolReadOnly Then Me.btnDel.Enabled = False Me.btnSave.Enabled = False End If End Sub
|