如下代码:
   If NulltoStr(txtChkPsw.Text) <> NulltoStr(labPassword.Caption) Then
       labPassword.Caption = txtChkPsw.Text
       If DatMain.RecordSet.EditMode <> adEditNone Then
            DatMain.RecordSet.Update
            DatMain.Refresh
        End If
   End If说明:labPassWord标签控件与ADO控件是绑定在一起的,txtChkPsw文本控件没有与ADO绑定,以上这一种情况出现时,DatMain.RecordSet.EditMode = adEditNone ,记录集并没有改变,请问各位高手,这一种情况该如何处理.谢谢!!!

解决方案 »

  1.   

    VB6中的数据绑定做的还不是很完美,如果喜欢这种方式,还是用.net 
    .net中的数据库绑定技术才算是比较成熟。用VB6,我建议你还是用代码一行一行的写。
    先建立Connection 
    然后检索或者修改数据……言归正传,你的逻辑似乎有点不妥:
    DatMain.RecordSet.EditMode = adEditNone则
    If DatMain.RecordSet.EditMode <> adEditNone Then
      DatMain.RecordSet.Update
      DatMain.Refresh
    End If
    就不会执行了,不是吗?
      

  2.   


    VERSION 5.00
    Begin VB.Form frmxy 
       Caption         =   "XY曲线值"
       ClientHeight    =   1560
       ClientLeft      =   1110
       ClientTop       =   450
       ClientWidth     =   5520
       LinkTopic       =   "Form2"
       ScaleHeight     =   1560
       ScaleWidth      =   5520
       Begin VB.CommandButton cmdClose 
          Caption         =   "关闭(&C)"
          Height          =   300
          Left            =   4440
          TabIndex        =   10
          Top             =   1020
          Width           =   975
       End
       Begin VB.CommandButton cmdUpdate 
          Caption         =   "更新(&U)"
          Height          =   300
          Left            =   3360
          TabIndex        =   9
          Top             =   1020
          Width           =   975
       End
       Begin VB.CommandButton cmdRefresh 
          Caption         =   "刷新(&R)"
          Height          =   300
          Left            =   2280
          TabIndex        =   8
          Top             =   1020
          Width           =   975
       End
       Begin VB.CommandButton cmdDelete 
          Caption         =   "删除(&D)"
          Height          =   300
          Left            =   1200
          TabIndex        =   7
          Top             =   1020
          Width           =   975
       End
       Begin VB.CommandButton cmdAdd 
          Caption         =   "添加(&A)"
          Height          =   300
          Left            =   120
          TabIndex        =   6
          Top             =   1020
          Width           =   975
       End
       Begin VB.Data Data1 
          Align           =   2  'Align Bottom
          Connect         =   ""
          DatabaseName    =   "E:\dB.mdb"
          DefaultCursorType=   0  '缺省游标
          DefaultType     =   2  '使用 ODBC
          Exclusive       =   0   'False
          Height          =   285
          Left            =   0
          Options         =   0
          ReadOnly        =   0   'False
          RecordsetType   =   1  'Dynaset
          RecordSource    =   "XY曲线值"
          Top             =   1275
          Width           =   5520
       End
       Begin VB.TextBox txtFields 
          DataField       =   "Y"
          DataSource      =   "Data1"
          Height          =   285
          Index           =   2
          Left            =   2040
          TabIndex        =   5
          Top             =   680
          Width           =   1935
       End
       Begin VB.TextBox txtFields 
          DataField       =   "X"
          DataSource      =   "Data1"
          Height          =   285
          Index           =   1
          Left            =   2040
          TabIndex        =   3
          Top             =   360
          Width           =   1935
       End
       Begin VB.TextBox txtFields 
          DataField       =   "时间"
          DataSource      =   "Data1"
          Height          =   285
          Index           =   0
          Left            =   2040
          TabIndex        =   1
          Top             =   40
          Width           =   1935
       End
       Begin VB.Label lblLabels 
          Caption         =   "Y:"
          Height          =   255
          Index           =   2
          Left            =   120
          TabIndex        =   4
          Top             =   700
          Width           =   1815
       End
       Begin VB.Label lblLabels 
          Caption         =   "X:"
          Height          =   255
          Index           =   1
          Left            =   120
          TabIndex        =   2
          Top             =   380
          Width           =   1815
       End
       Begin VB.Label lblLabels 
          Caption         =   "时间:"
          Height          =   255
          Index           =   0
          Left            =   120
          TabIndex        =   0
          Top             =   60
          Width           =   1815
       End
    End
    Attribute VB_Name = "frmxy"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Option ExplicitPrivate Sub cmdAdd_Click()
      Data1.Recordset.AddNew
    End SubPrivate Sub cmdDelete_Click()
      '如果删除记录集的最后一条记录
      '记录或记录集中唯一的记录
      Data1.Recordset.Delete
      Data1.Recordset.MoveNext
    End SubPrivate Sub cmdRefresh_Click()
      '这仅对多用户应用程序才是需要的
      Data1.Refresh
    End SubPrivate Sub cmdUpdate_Click()
      Data1.UpdateRecord
      Data1.Recordset.Book = Data1.Recordset.LastModified
    End SubPrivate Sub cmdClose_Click()
      Unload Me
    End SubPrivate Sub Data1_Error(DataErr As Integer, Response As Integer)
      '这就是放置错误处理代码的地方
      '如果想忽略错误,注释掉下一行代码
      '如果想捕捉错误,在这里添加错误处理代码
      MsgBox "数据错误事件命中错误:" & Error$(DataErr)
      Response = 0  '忽略错误
    End SubPrivate Sub Data1_Reposition()
      Screen.MousePointer = vbDefault
      On Error Resume Next
      '这将显示当前记录位置
      '为动态集和快照
      Data1.Caption = "记录:" & (Data1.Recordset.AbsolutePosition + 1)
      '对于 Table 对象,当记录集创建后并使用下面的行时,
      '必须设置 Index 属性
      'Data1.Caption = "记录:" & (Data1.Recordset.RecordCount * (Data1.Recordset.PercentPosition * 0.01)) + 1
    End SubPrivate Sub Data1_Validate(Action As Integer, Save As Integer)
      '这是放置验证代码的地方
      '当下面的动作发生时,调用这个事件
      Select Case Action
        Case vbDataActionMoveFirst
        Case vbDataActionMovePrevious
        Case vbDataActionMoveNext
        Case vbDataActionMoveLast
        Case vbDataActionAddNew
        Case vbDataActionUpdate
        Case vbDataActionDelete
        Case vbDataActionFind
        Case vbDataActionBook
        Case vbDataActionClose
      End Select
      Screen.MousePointer = vbHourglass
    End SubMS自动生成的绑定代码~~
      

  3.   

    对,如果是这样是不会再往下执行的,是你误解我意思啦;我的意思是说,如果我是给控制赋值如:labPassword.Caption = txtChkPsw.Text,这样子的话,DatMain.RecordSet.EditMode的值不会是adEditInProgress,RecordSet集里的值没有发生任何变化,它不等于labPassword.Caption的值,这样子就更新不了数据库,DatMain.RecordSet.EditMode的值还是adEditNone。
         但是如果我绑定下的是TextBox的话,我手工改动TextBox的Text值的话呢,DatMain.RecordSet.EditMode的值会是adEditInProgress或其他值,这样子就可以更新数据库啦,反之还是不行。
      

  4.   


    VERSION 5.00
    Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
    Begin VB.Form FrmXY 
       Caption         =   "XY曲线值"
       ClientHeight    =   5085
       ClientLeft      =   1110
       ClientTop       =   450
       ClientWidth     =   6675
       KeyPreview      =   -1  'True
       LinkTopic       =   "Form2"
       ScaleHeight     =   5085
       ScaleWidth      =   6675
       Begin VB.CommandButton cmdClose 
          Cancel          =   -1  'True
          Caption         =   "关闭(&C)"
          Height          =   300
          Left            =   5340
          TabIndex        =   0
          Top             =   3960
          Width           =   1080
       End
       Begin MSHierarchicalFlexGridLib.MSHFlexGrid MSHFlexGrid1 
          DragIcon        =   "FrmXY.frx":0000
          Height          =   3840
          Left            =   60
          TabIndex        =   1
          Top             =   60
          Width           =   6360
          _ExtentX        =   11218
          _ExtentY        =   6773
          _Version        =   393216
          BackColor       =   16777215
          ForeColor       =   0
          Rows            =   20
          Cols            =   4
          GridColor       =   12632256
          GridColorFixed  =   -2147483632
          WordWrap        =   -1  'True
          AllowBigSelection=   0   'False
          FocusRect       =   0
          HighLight       =   0
          AllowUserResizing=   1
          FormatString    =   "|时间|X|Y"
          _NumberOfBands  =   1
          _Band(0).Cols   =   4
          _Band(0).GridLineWidthBand=   1
          _Band(0).TextStyleBand=   0
       End
    End
    Attribute VB_Name = "FrmXY"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Option ExplicitPrivate Const MARGIN_SIZE = 60      ' 单位为缇
    ' 数据绑定变量
    Private datPrimaryRS As ADODB.Recordset' 能列排序变量
    Private m_iSortCol As Integer
    Private m_iSortType As Integer' 列拖拽变量
    Private m_bDragOK As Boolean
    Private m_iDragCol As Integer
    Private xdn As Integer, ydn As IntegerPrivate Sub Form_Load()    Dim sConnect As String
        Dim sSQL As String
        Dim dfwConn As ADODB.Connection    ' 设置字符串
        sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Password='';User ID=Admin;Data Source=E:\dB.mdb;Mode=Share Deny None;Extended Properties='';Jet OLEDB:System database='';Jet OLEDB:Registry Path='';Jet OLEDB:Database Password='';Jet OLEDB:Engine Type=4;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password='';Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False"
        sSQL = "select 时间,X,Y from XY曲线值 Order by 时间"    ' 打开连接
        Set dfwConn = New Connection
        dfwConn.Open sConnect    ' 使用提供的集合创建 recordset
        Set datPrimaryRS = New Recordset
        datPrimaryRS.CursorLocation = adUseClient
        datPrimaryRS.Open sSQL, dfwConn, adOpenForwardOnly, adLockReadOnly    Set MSHFlexGrid1.DataSource = datPrimaryRS    With MSHFlexGrid1        .Redraw = False
            ' 设置网格列宽度
            .ColWidth(0) = 300
            .ColWidth(1) = 2175
            .ColWidth(2) = -1
            .ColWidth(3) = -1        ' 设置网格样式
            .AllowBigSelection = True
            .FillStyle = flexFillRepeat        ' 将标头作成粗体
            .Row = 0
            .Col = 0
            .RowSel = .FixedRows - 1
            .ColSel = .Cols - 1
            .CellFontBold = True        .AllowBigSelection = False
            .FillStyle = flexFillSingle
            .Redraw = True    End WithEnd SubPrivate Sub MSHFlexGrid1_DragDrop(Source As Control, X As Single, Y As Single)
    '-------------------------------------------------------------------------------------------
    ' 网格中 DragDrop, MouseDown, MouseMove, 和 MouseUp 事件代码能进行列拖拽
    '-------------------------------------------------------------------------------------------    If m_iDragCol = -1 Then Exit Sub    ' 现在不能拖拽
        If MSHFlexGrid1.MouseRow <> 0 Then Exit Sub
        If MSHFlexGrid1.FixedCols = 1 And MSHFlexGrid1.MouseCol = 0 Then Exit Sub    With MSHFlexGrid1
            .Redraw = False
            .ColPosition(m_iDragCol) = .MouseCol
            .Redraw = True
        End WithEnd SubPrivate Sub MSHFlexGrid1_MouseDown(Button As Integer, shift As Integer, X As Single, Y As Single)
    '-------------------------------------------------------------------------------------------
    ' 网格中 DragDrop, MouseDown, MouseMove, 和 MouseUp 事件代码能进行列拖拽
    '-------------------------------------------------------------------------------------------    If MSHFlexGrid1.MouseRow <> 0 Then Exit Sub
        If MSHFlexGrid1.MouseCol = 0 And MSHFlexGrid1.FixedCols = 1 Then Exit Sub    xdn = X
        ydn = Y
        m_iDragCol = -1     ' 清除拖拽标志
        m_bDragOK = TrueEnd SubPrivate Sub MSHFlexGrid1_MouseMove(Button As Integer, shift As Integer, X As Single, Y As Single)
    '-------------------------------------------------------------------------------------------
    ' 网格中 DragDrop, MouseDown, MouseMove, 和 MouseUp 事件代码能进行列拖拽
    '-------------------------------------------------------------------------------------------    ' 测试是否能够开始拖拽
        If Not m_bDragOK Then Exit Sub
        If Button <> 1 Then Exit Sub                        ' 错误按钮
        If m_iDragCol <> -1 Then Exit Sub                   ' 已经开始拖拽
        If Abs(xdn - X) + Abs(ydn - Y) < 50 Then Exit Sub   ' 移得不够
        If MSHFlexGrid1.MouseRow <> 0 Then Exit Sub         ' 必须拖拽标头    ' 如果到达这则开始拖拽
        m_iDragCol = MSHFlexGrid1.MouseCol
        MSHFlexGrid1.Drag vbBeginDragEnd SubPrivate Sub MSHFlexGrid1_MouseUp(Button As Integer, shift As Integer, X As Single, Y As Single)
    '-------------------------------------------------------------------------------------------
    ' 网格中 DragDrop, MouseDown, MouseMove, 和 MouseUp 事件代码能进行列拖拽
    '-------------------------------------------------------------------------------------------    m_bDragOK = FalseEnd SubPrivate Sub MSHFlexGrid1_DblClick()
    '-------------------------------------------------------------------------------------------
    ' 网格的 DblClick 事件代码能进行列排序
    '-------------------------------------------------------------------------------------------    Dim i As Integer    ' 仅在单击固定行时进行排序
        If MSHFlexGrid1.MouseRow >= MSHFlexGrid1.FixedRows Then Exit Sub    i = m_iSortCol                  ' 保存旧列
        m_iSortCol = MSHFlexGrid1.Col   ' 设置新列    ' 递增排序类型
        If i <> m_iSortCol Then
            ' 如果在新的列上单击鼠标,开始升序排序
            m_iSortType = 1
        Else
            ' 如果在相同列单击鼠标,则进行升序和降序排序的转换。
            m_iSortType = m_iSortType + 1
        If m_iSortType = 3 Then m_iSortType = 1
        End If    DoColumnSortEnd SubSub DoColumnSort()
    '-------------------------------------------------------------------------------------------
    ' 作 Exchange-type 排序在列 m_iSortCol
    '-------------------------------------------------------------------------------------------    With MSHFlexGrid1
            .Redraw = False
            .Row = 1
            .RowSel = .Rows - 1
            .Col = m_iSortCol
            .Sort = m_iSortType
            .Redraw = True
        End WithEnd SubPrivate Sub Form_Resize()    Dim sngButtonTop As Single
        Dim sngScaleWidth As Single
        Dim sngScaleHeight As Single    On Error GoTo Form_Resize_Error
        With Me
            sngScaleWidth = .ScaleWidth
            sngScaleHeight = .ScaleHeight        ' 移动“关闭”按钮到右下角
            With .cmdClose
                    sngButtonTop = sngScaleHeight - (.Height + MARGIN_SIZE)
                    .Move sngScaleWidth - (.Width + MARGIN_SIZE), sngButtonTop
            End With        .MSHFlexGrid1.Move MARGIN_SIZE, _
                MARGIN_SIZE, _
                sngScaleWidth - (2 * MARGIN_SIZE), _
                sngButtonTop - (2 * MARGIN_SIZE)    End With
        Exit SubForm_Resize_Error:
        ' 避免负值错误
        Resume NextEnd Sub
    Private Sub cmdClose_Click()    Unload MeEnd Sub再来一段~~
    另存为XX.frm 就可以了。
      

  5.   

    那你就用Text 控件绑定就是了,不想让它编辑的话,用Lock属性或者Enable就是了
      

  6.   

    我的意思是如果是给绑定的控件赋值,这一种行为,都不会产生(DatMain.RecordSet.EditMode <> adEditNone)=True这一种情况,执行不了更新. 
      

  7.   

    唉~~
    那你就用
    Connection.Exec("Update ……")
      

  8.   


    可以帮我解决我的问题吗?
       cn.Open "Provider=Microsoft.Jet.oledb.4.0;Data Source=" & App.Path & "\test.mdb"
       rs1.CursorLocation = adUseClient
       rs1.Open "订单信息", cn, adOpenKeyset, adLockOptimistic
       Set DataGrid1.DataSource = rs1我想将这里 数据表 订单信息 里面 id 字段 以降序 排列 请问各位 如何添加代码!我发不到贴,谢谢!
      

  9.   

    那你得仔细学习sql了,sort by
      

  10.   

    使用ADODB对象,更新了就断开连接,需要更新时在连接数据库。
      

  11.   

    楼主没有理解控件的用途。简单绑定情况下,如果数据源数据刷新或移动记录,会自动给每个被绑定的控件赋值。
    但是如何将控件的内容更新到数据源,是由控件自己决定的,因为只有控件自己知道什么时候数据被修改了、并且决定修改的数据是否合法,如果没有更新或不合法,当然不用更新。甚至控件可以设计成始终不更新的。而从绑定的用途上,TextBox 被设计为可更新的绑定,Label 被设计为只读的绑定(这时对 Label 的修改可以认为只是对显示进行格式化)。