大家帮我看看~adodc2是用来添加数据的。adodc1是用来在datagrid里显示数据的。但是adodc2添加玩数据后为什么datagrid不能更新呢?
    If Command1.Caption = "确定" Then
        If Trim(Text1.Text) = "" Or Trim(Combo1.Text) = "" Or Trim(Combo3.Text) = "" Or Trim(Combo2.Text) = "" Or Trim(Text2.Text) = "" Or Trim(Text3.Text) = "" Or Trim(Text4.Text) = "" Or Trim(Text5.Text) = "" Then
            MsgBox "试题资料不能为空,请填写!"
        Else
            Adodc2.RecordSource = "select * from testdes where code='" + Text1.Text + "'"
            Adodc2.Refresh
            If Adodc2.Recordset.RecordCount > 0 Then
                MsgBox "该试题代码已经存在,请重新输入!", 48, "提示信息"
                Text1.Text = ""
                Text1.SetFocus
            Else
                With Adodc2.Recordset
                    .AddNew
                    .Fields("Code") = Text1.Text
                    .Fields("stdes") = Text2.Text
                    .Fields("stanswer") = Text3.Text
                    .Fields("writep") = Text5.Text
                    .Fields("stmemo") = Text6.Text
                    .Fields("testpoint") = Text4.Text
                    .Fields("inputp") = Form1.pName
                    .Fields("inputtime") = Format(Now, "yy-mm-dd hh:mm:ss")
                    .Fields("unit") = Left(Text4.Text, InStr(Text4.Text, "-") - 1)
                    .Fields("itemid") = Combo1.ItemData(Combo1.ListIndex)
                    .Fields("lecode") = Combo2.ItemData(Combo2.ListIndex)
                    .Fields("sttype") = Combo3.Text
                End With
                
                If MsgBox("您确定要保存吗?", vbOKCancel, "提示") = 1 Then
                    Adodc2.Recordset.Update
                    Adodc1.refresh
                    Datagrid1.refesh
                    MSG = MsgBox("试题已保存", , "提示")
                End If
            End If
                Command1.Caption = "添加"
                Command2.Enabled = True
                Command3.Enabled = True
                Text1.Enabled = False
                Text2.Enabled = False
                Text3.Enabled = False
                Text4.Enabled = False
                Text5.Enabled = False
                Text6.Enabled = False
                Combo1.Enabled = False
                Combo2.Enabled = False
                Combo3.Enabled = False
        End If
    Else
        Command1.Caption = "确定"
        Command2.Enabled = False
        Command3.Enabled = False
        Text1.Enabled = True
        Text2.Enabled = True
        Text3.Enabled = True
        Text4.Enabled = True
        Text5.Enabled = True
        Text6.Enabled = True
        Combo1.Enabled = True
        Combo2.Enabled = True
        Combo3.Enabled = True
    End If

解决方案 »

  1.   

    adodc1在adodc2添加数据成功后,重新刷新记录集
      

  2.   

    为什么要用两个adodc???一般来说一个就足够了。。
      

  3.   

    谢谢zuoxingyu。问题已经解决了。。
      

  4.   

    一个adodc怎么怎么做啊?能教教我吗?
    我是说让不显示的字段同时也要添加数据进去,但是用一个每次添加的时候没显示的字段添加数据就报错。
      

  5.   

    留言收到你不显示的字段,应该在datagrid里隐藏起来,这样只用一个adodc就可以了。。例如把第一个字段隐藏起来:
    DataGrid1.Columns(0).Visible = False