我想将sqlserver中的数据倒出到文本中,再将文本中的数据到入sqlserver中,如何实现呢!

解决方案 »

  1.   

    试试RstPrm.GetString的方法
    Public Sub SaveRecInText(RstPrm As ADODB.Recordset, _FileSpec As String, RowCount As Long, _ColDeli As String, RowDeli As String, _NullRep As String)
    Dim sBuffer As StringDim FileNum As LongsBuffer = RstPrm.GetString(adClipString, RowCount, ColDeli, RowDeli, NullRep)
    'Remove the file first if it exists.If Len(Dir(FileSpec)) > 0 ThenKill FileSpecEnd If'FileNum = FreeFileOpen FileSpec For Binary As FileNumPut FileNum, , sBufferClose FileNum'End Sub
      

  2.   

    再将文本中的数据到入sqlserver中??
    创建存储过程,使用bulk insert非常方便,而且速度快
    CREATE PROCEDURE insert_from_text
    AS
    begin
    bulk insert dcss_dwjbda
           from 'c:\trans.txt'
        with(
    FIELDTERMINATOR = '|',
    ROWTERMINATOR = '|\n',
    FIRSTROW = 2
    )
    endvb中调用
    rs.open "insert_from_text",conn
      

  3.   

    导入,对文本建立数据源
    Public Function Read_Text_File() As ADODB.Recordset      Dim rs As ADODB.Recordset
          Set rs = New ADODB.Recordset
          Dim conn As ADODB.Connection
          Set conn = New ADODB.Connection
          conn.Open "DRIVER={Microsoft Text Driver (*.txt; *.csv)};" & _
                      "DBQ=" & App.Path & ";", "", ""      rs.Open "select * from [test#txt]", conn, adOpenStatic, _
                      adLockReadOnly, adCmdText
          Set Read_Text_File = rs
          Set rs = Nothing
          Set conn = Nothing
    End FunctionPrivate Sub cmdReadTXT_Click()
          Set dgData.DataSource = Read_Text_File()
          Set obj = Nothing
    End Sub然后,读取,一条一条插入
    比较慢