我已经把MSFlexGrid控件连上了数据库,可以显示数据,并且我也在MSFlexGrid中加入了一个textbox,可以实现修改MSFlexGrid中网格的内容,但是我知道如何把这个东西与数据库连起来,我修改的东西没有办法加到数据库中!我遇到的最大的问题是不知道如何定位!我可以把textbox中的数据提出来,但是不知道如何确定他的位置!就好像
nuber  name  age
01    jim     10
02    jake    11
03    mike    9
学号是主键。当我要修改jim的年龄时,我已经得到了数据,但是如何确定它的位置呢!应该如何操作!(我用的时DAO)

解决方案 »

  1.   

    确定谁的位置???
    if Text.位置 then
       text1.left=msflexgrid1.CellLeft
       .....
    elseif 数据库中当前记录的位置
       rt.move msflexgrid1.row,adBookFirst
    end if
      

  2.   

    to:tygh2000(峰)
        谢谢你上次的答复!
    确定网格的位置,也就要修改的单元格的位置!
    能不能写的再详细一点?
    下面是我的源代码:
    Private Sub cmdcancel_Click()
    Unload Me
    End SubPrivate Sub Form_Load()
    Dim dbname As String
    Dim db As Database
    Dim qdef As QueryDef
    Dim td As TableDef    ' Open the database.
        dbname = App.Path
        If Right$(dbname, 1) <> "\" Then dbname = dbname & "\"
        dbname = dbname & "fina.mdb"
        Set db = OpenDatabase(dbname)    ' List the table names.
        For Each td In db.TableDefs
            ' Do not allow the system tables.
            If Left$(td.Name, 4) <> "MSys" Then _
                List1.AddItem td.Name
        Next td    db.Close    ' Attach the Data control to the database.
        Data1.DatabaseName = dbname
        txtinput.Visible = False
    End SubPrivate Sub List1_Click()
    Dim table_name As String
    Dim sql As String
        
        table_name = List1.List(List1.ListIndex)
        sql = "SELECT * FROM " & table_name
        Data1.Caption = table_name
        Data1.RecordSource = sql
        Data1.Visible = True
        
       ' MSFlexGrid1.DataSource = Data1
        'MSFlexGrid1.DataField = List1.List(List1.ListIndex)
        Data1.Refresh
        
        ' Make the Data and DBGrid controls visible.
        
        MSFlexGrid1.Visible = TrueEnd SubPrivate Sub MSFlexGrid1_DblClick()
    Dim c As Integer, r As IntegerWith MSFlexGrid1
        c = .Col: r = .Row
            txtinput.Left = .Left + .ColPos(c)
            txtinput.Top = .Top + .RowPos(r)
            txtinput.Width = .ColWidth(c)
            txtinput.Height = .RowHeight(r)
            txtinput = .Text
            txtinput.Visible = True
    End WithEnd SubPrivate Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        Call MSFlexGrid1_DblClick
    End If
    End SubPrivate Sub txtinput_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyEscape Then
        txtinput.Visible = False
        MSFlexGrid1.SetFocus
        Exit Sub
    End If
    If KeyAscii = vbKeyReturn Then
        MSFlexGrid1.Text = txtinput.Text
        txtinput.Visible = False
        MSFlexGrid1.SetFocus
    End If
    End SubPrivate Sub txtinput_LostFocus()
    txtinput.Visible = False
    MSFlexGrid1.SetFocus
    End Sub
    在界面里有一个listbox控件,一个MSFlexGrid控件,一个data控件。
      

  3.   

    用DATAGRID控件+adodata吧,方便得多,什么年代了还用DBDATA控件