我用vb与SQL数据库连接成功(可以登陆数据库并可以修改数据库中的用户信息表的内容),但是不能通过MSFlexgrid控件显示其他的数据表的内容,也不可以对其他表进行操作(运行时vb代码没有报错),怀疑做vb工程时References的驱动少了,但不知道vb与SQL数据库连接需要多少References的驱动(最好能有图示),不知哪位大虾能回答我的问题,希望能够尽快回复,在此我谢谢了!!!!!!!!!!!!

解决方案 »

  1.   

    只要你能连接上数据库了就可以对它所有的表进行操作了,只是SQL语句不同而已楼上说的SP6没打,就不能访问数据库了吗?MSFlexgrid不能显示其他数据表,你用的是不是数据绑定,磅定是在设计时候还是运行的时候?估计是在设计时候做的,以后对数据库其他表操作就没办法了,因为你把数据原写死了
      

  2.   

    我用的不是数据绑定,代码如下,求哪位大虾能帮我看看
    主模块相关代码:
    Public Function ConnectString() _
       As String
    'returns a DB ConnectString
       ConnectString = "FileDSN=大华塑业备件数据库.dsn;UID=sa;PWD=sa"
    End Function
    Public Function ExecuteSQL(ByVal SQL _
       As String, MsgString As String) _
       As ADODB.Recordset
    'executes SQL and returns Recordset
       Dim cnn As ADODB.Connection
       Dim rst As ADODB.Recordset
       Dim sTokens() As String
       
       On Error GoTo ExecuteSQL_Error
       
       sTokens = Split(SQL)
       Set cnn = New ADODB.Connection
       cnn.Open ConnectString
       If InStr("INSERT,DELETE,UPDATE,EXECUTE", _
          UCase$(sTokens(0))) Then
          cnn.Execute (SQL)
          MsgString = sTokens(0) & _
             " query successful"
       Else
          Set rst = New ADODB.Recordset
          rst.Open Trim$(SQL), cnn, _
             adOpenKeyset, _
             adLockOptimistic
          'rst.MoveLast     'get RecordCount
          Set ExecuteSQL = rst
          MsgString = "查询到" & rst.RecordCount & _
             " 条记录 "
       End If
    ExecuteSQL_Exit:
       Set rst = Nothing
       Set cnn = Nothing
       Exit Function
       
       
    ExecuteSQL_Error:
       MsgString = "查询错误: " & _
          Err.Description
       Resume ExecuteSQL_Exit
    End Function
    窗体相关代码:
    Private Sub From_Load()
        ShowTile
        ShowData
        'cnn.Open ConnectString
       ' DisplayGrid
    End Sub
    Private Sub ShowTile()
        Dim i As Integer
       With MSFlexGrid1
            '设置列数目
           .Cols = 8
            .TextMatrix(0, 1) = "物资编号"
            .TextMatrix(0, 2) = "名称"
           .TextMatrix(0, 3) = "型号"
           .TextMatrix(0, 4) = "规格"
           .TextMatrix(0, 5) = "计量单位"
           .TextMatrix(0, 6) = "库存量"
           .TextMatrix(0, 7) = "存放位置"
            .TextMatrix(0, 8) = "备注"
           ' 固定表头
            .FixedRows = 1
            '设置各列的对齐方式
            For i = 0 To 8
                .ColAlignment(i) = 0
            Next i
            '表头项居中
            .FillStyle = flexFillRepeat
            .Col = 0
            .Row = 0
            .RowSel = 1
            .ColSel = .Cols - 1
            .CellAlignment = 4
            ''设置单元大小
           .ColWidth(0) = 1000
            .ColWidth(1) = 1000
            .ColWidth(2) = 1000
            .ColWidth(3) = 1000
            .ColWidth(4) = 1000
            .ColWidth(5) = 1000
            .ColWidth(6) = 1000
            .ColWidth(7) = 1000
            .ColWidth(8) = 1000
            .Row = 1
        End With
    End Sub
    Private Sub ShowData()
        Dim j As Integer
        Dim i As Integer
        Dim MsgText As String
        txtSQL = "SELECT * FROM 库存信息表"
        Set mrc = ExecuteSQL(txtSQL, MsgText)
            With MSFlexGrid1
            .Rows = 1
          
            
            Do While Not mrc.EOF
               .Rows = .Rows + 1
                For i = 1 To mrc.Fields.Count
                   '判断数据项是否为空
                    If Not IsNull(Trim(mrc.Fields(i - 1))) Then
                    '根据数据项类型进行
                    Select Case mrc.Fields(i - 1).Type
                        '如果是日期型数据,按照"年-月-日"格式化
                        Case adDBData
                            .TextMatrix(.Rows - 1, i) = Format(mrc.Fields(i - 1) & "", "yyyy-mm-dd")
                        Case Else
                           .TextMatrix(.Rows - 1, i) = mrc.Fields(i - 1) & ""
                    End Select
                    End If
                Next i
               mrc.MoveNext
            Loop
            
            
        End With
        mrc.Close
    End Sub
    操作相关代码:
    Private Sub cmdSave_Click()
        Dim intCount As Integer
        Dim sMeg As String
        Dim MsgText As String
        Dim mrc As ADODB.Recordset
        '判断输入内容是否为空
                
        '判断是否输入数字
         
            '添加判断是否有相同的ID记录
            If gint库存信息设置修改mode = 1 Then
                txtSQL = "select * FROM [dbo].[库存信息表] where 物资编号='" & Trim(txtFields(0)) & "'"
                Set mrc = ExecuteSQL(txtSQL, MsgText)
                If mrc.EOF = False Then
                    MsgBox "已经存在此物资编号的记录!", vbOKOnly + vbExclamation, "警告"
                    txtFields(0).SetFocus
                    Exit Sub
                End If
                mrc.Close
            End If
            '先删除已有记录
            txtSQL = "delete from 库存信息表 where 物资编号='" & Trim(txtFields(0)) & " '"
            Set mrc = ExecuteSQL(txtSQL, MsgText)
            '再加入新记录
            txtSQL = "execute 库存信息表_setup'" '调用事先建立的SQL存储过程
            For intCount = 0 To 7
                txtSQL = txtSQL & Trim(txtFields(intCount)) & "','"
            txtSQL = txtSQL & Trim(txtFields(intCount)) & ","
            Next intCount
            '执行SQL语句
            Set mrc = ExecuteSQL(txtSQL, MsgText)
            '更新窗体
            If gint库存信息设置修改mode = 1 Then
                MsgBox "添加记录成功!", vbOKOnly + vbExclamation, "添加记录"
                For intCount = 0 To 7
                    txtFields(intCount) = ""
                Next intCount
                Unload Me
                frm库存信息设置修改.txtSQL = "select* FROM [dbo].[库存信息表]"
                frm库存信息设置修改.Show
            ElseIf gint库存信息设置修改mode = 2 Then
                Unload Me
                frm库存信息设置修改.txtSQL = "select* FROM [dbo].[库存信息表]"
                frm库存信息设置修改.Show
            End If
    End Sub
      

  3.   

    用MSHFlexgrid显示行不行??
    是显示不出来吗?
      

  4.   

    就是用MSFlexGrid不能显示,可以修改数据库中的用户信息表的内容,但是不能对其他表进行操作,有哪位高手能回答吗?相关程序代码已经在上面了
      

  5.   

    不可能吧,应该是你的MSFlexGrid控件应用不当.
      

  6.   

    能不能详细点?MSFlexGrid控件应用有什么特别要求吗?
      

  7.   

    我很少用MSFlexGrid,我还比较古老用DataGrid,如果你要用它,我可以试着做做!