我想请教大家几个问题?!
1.用VB做了数据库SQL连接,查询数据用的ADODC控件绑定了datagrid控件,这样要是安装到其他机器上还得在其机器上做数据源,用什么办法可以不用数据源?做到用msflexgrid控件显示数据,只要在客户机器上安装就可以使用不用再设置数据源,最后能举例有代码。
2.VB做的在本地机器上选择EXCEL文件然后上传到远程数据库SQL2000,但现在我只能实现在SQL服务器上的EXCEL文件才能传到本机的数据库中,不能实现远程的上传??@大家有没有办法可以实现的代码或例子,大家有没有做过?3..还有一个问题都困扰了我一个月了,仍没解决,如果 有能解决的要多少给多少分。
就是我用VB部件中的office web components其中有一组件spreadsheet,界面在VB中类似EXCEL表格,我想用它来传数据到SQL点击上传后就可以传到SQL对应的字段中!!!

解决方案 »

  1.   

    使用ADO,不要用ADODC控件了。直接用代码,更为灵活。
    联接字符串,你可以参考(全):
    www.connnectionstrings.com代码例下:
    dim cn as adodb.connection
    dim rs as adodb.recordsetset cn=new adodb.connection
    cn.open "联接串,看你用什么数据库,根据上面网站,找一个"set rs=new adodb.recordset
    rs.open "select * from customer" ,cn,1,3
    set mshflexgrid.datasource=rs
    ...rs.close
    set rs=nothing
    cn.close
    set cn=nothing
    代码大致这样子,你查询一下本版数据库分板块,很多这类代码。
      

  2.   

    上面代码可以有多种使用形式,比如,上面也可以直接这样:set cn=new adodb.connection
    cn.open "..."
    set mshflexgrid.datasource=cn.execute("select * from customer")
    ...
      

  3.   

    我也在学用spreadsheet……给你几个方法,是我自己写的,也许不怎么样,抛砖引玉吧。
    Public Function ConnectString() As String
          ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=admin;password=;Data Source=./HelpDesk.mdb;"
    End Function
    Public Function SelectSQL(ByVal sSQL As String) As ADODB.Recordset
       Dim cnn As ADODB.Connection
       Dim rst As ADODB.Recordset
       
       On Error GoTo SelectSQL_Exit   Set cnn = New ADODB.Connection
       cnn.ConnectionString = ConnectString
       Set rst = New ADODB.Recordset
       cnn.Open
       rst.Open Trim$(sSQL), cnn, _
        adOpenKeyset, _
        adLockOptimistic
       Set SelectSQL = rst
    SelectSQL_Exit:
       Set rst = Nothing
       Set cnn = Nothing
       Exit Function
    End Function
    Private Function getColNum(sheet As Spreadsheet, headerRow As Integer, startCol As Integer) As Integer
    'if getcolnum = 0 means there is no cols
        getColNum = 0
        For i = startCol To 65535
            If sheet.Cells(headerRow, i) = "" Then
                If i = startCol Then
                    getColNum = 0
                Else
                    getColNum = i - 1
                End If
                Exit Function
            End If
        Next i
    End FunctionPrivate Sub store_data(sheet As Spreadsheet, headerRow As Integer, startCol As Integer, popTable As String, keyCol As Integer)
    On Error GoTo err
        Dim msg As String
        msg = "Unexpect error!"
        If keyCol < startCol Then
            msg = "Please move the key column behind the start column!"
            GoTo err
        End If
        Dim cols As Integer
        cols = 1
        Dim hasMoreRow As Boolean
        cols = getColNum(sheet, headerRow, startCol)
        If cols = 0 Then
            msg = "There is no columns' name. Please check it!"
            GoTo err
        End If
        For i = headerRow + 1 To 65535
            If Len(Trim(sheet.Cells(i, keyCol))) = 0 Then
                GoTo end_of_data
            End If
            sSQL = "select * from " & popTable & " where " & sheet.Cells(headerRow, keyCol) & " = " & sheet.Cells(i, keyCol)
            Set rs = New ADODB.Recordset
            Set rs = SelectSQL(sSQL)
            If rs.EOF Then
                rs.AddNew
                rs.Fields("key") = newKyeForCase()
            End If
            hasMoreRow = False
            For j = startCol To startCol + cols - 1
                If Len(Trim(sheet.Cells(i, j).Text)) > 0 Then
                    rs.Fields(Trim(sheet.Cells(headerRow, j))) = Trim(sheet.Cells(i, j))
                    hasMoreRow = True
                End If
            Next j
            If hasMoreRow Then
                rs.Update
            Else
                rs.CancelUpdate
                GoTo end_of_data
            End If
            rs.Close
            Set rs = Nothing
        Next i
    end_of_data:
        Set rs = Nothing
        sSQL = ""
        msg = ""
        Exit Sub
    err:
        MsgBox err
        MsgBox msg
    End Sub