
Option Explicit
Private mrc As New ADODB.Recordset
Private Cn As New ADODB.Connection
Private IfUpdate As Boolean
Private Sub Command1_Click()
Dim SQL As String
    
On Error GoTo ProcError
    
    IfUpdate = False
    
    '''''''''''生成SQL语句
    
    SQL = "序号=" & Text1.Text & ","
    SQL = SQL & "姓名='" & text2.Text & "',"
    
    '一次类推,一般使用text1控件数组,设可以对付很长字段的表
    
    ''''''''''''''执行修改
    
    Cn.Execute SQL
    IfUpdate = True
    MsgBox "修改成功!", 64
    
    
    ''''''''''''''''查询修改后的所有记录
    
    mrc.CursorLocation = adUseClient
    mrc.CursorType = adOpenDynamic
    mrc.LockType = adLockOptimistic
    
    SQL = "select * from result_Info order by student_ID "
    mrc.Open SQL, Cn
    
    
    ''''''''''''''''显示查询到的记录
    
    With myflexgrid
        .Rows = 2
        .CellAlignment = 4
        .TextMatrix(1, 0) = "考试编号"
        .TextMatrix(1, 1) = "学号"
        .TextMatrix(1, 2) = "姓名"
        .TextMatrix(1, 3) = "班号"
        .TextMatrix(1, 4) = "课程名称"
        .TextMatrix(1, 5) = "分数"
        
        
        Do While Not mrc.EOF
            .Rows = .Rows + 1
            .CellAlignment = 4
            .TextMatrix(.Rows - 1, 0) = mrc.Fields(0)
            .TextMatrix(.Rows - 1, 1) = mrc.Fields(1)
            .TextMatrix(.Rows - 1, 2) = mrc.Fields(2)
            .TextMatrix(.Rows - 1, 3) = mrc.Fields(3)
            .TextMatrix(.Rows - 1, 4) = mrc.Fields(4)
            .TextMatrix(.Rows - 1, 5) = mrc.Fields(5)
            mrc.MoveNext
        Loop
        
    End With
    
    ''邦定text控件与mrc
    
    Set Text1.DataSource = mrc
    Text1.DataField = mrc.Fields("考试编号").Name
    
     '一次类推
     
     
ProcExit:
    
    ''''''''''''''不管是否出错,均从这里退出,记住这是一个好习惯
    
    Exit Sub
ProcError:
    
    ''''''''''''''错误处理
    
    IfUpdate = False
    MsgBox "修改失败!", 48
    Resume ProcExit
    
End Sub
'当然,cn要提前连接
'''''老兄,你的谢谢我哟!
