当前位置:编程学习 > VB >>

vb SQLDMO BulkCopy ExportData ImportData


'' Command1_Click 能正常导出文件 aaaa.dat
'' MyTable1 与 MyTable2 表结构一模一样
Private Sub Command1_Click()
    Dim oServer     As New SQLDMO.SQLServer
    Dim oDatabase     As New Database
    Dim oBCP     As New SQLDMO.BulkCopy

    oServer.EnableBcp = True
    oServer.Connect ".", "sa", ""

    Set oDatabase = oServer.Databases("MyData")

    oBCP.DataFileType = SQLDMODataFile_CommaDelimitedChar
    oBCP.IncludeIdentityValues = True
    oBCP.UseExistingConnection = True
    
    oBCP.DataFilePath = "C:\aaaa.dat"
    oDatabase.Views.Item("MyTable1").ExportData(oBCP)    
    oServer.DisConnect
    oServer.Close

End Sub


Private Sub Command2_Click()
    Dim oServer     As New SQLDMO.SQLServer
    Dim oDatabase     As New Database
    Dim oBCP     As New SQLDMO.BulkCopy

    oServer.EnableBcp = True

    oServer.Connect ".", "sa", ""

    Set oDatabase = oServer.Databases.Item("MyData")
    
    oDatabase.DBOption.SelectIntoBulkCopy = True

    oBCP.DataFilePath = "C:\aaaa.dat"

    oBCP.DataFileType = SQLDMODataFile_CommaDelimitedChar
    oBCP.UseExistingConnection = True
    oBCP.ServerBCPKeepIdentity = True
    oBCP.IncludeIdentityValues = True

    oDatabase.Tables.Item("MyTable2").ImportData (oBCP)  ''在这里报错,  对象不支持改属性或方法
    '' ImportData  这个是不是这么写的?
    
    oBCP = Nothing
    
    MsgBox "oooooooooooook"

End Sub

--------------------编程问答--------------------

dim oRows as long 

oRows = oDatabase.Views.Item("MyTable1").ExportData(oBCP)    


oRows = oDatabase.Tables.Item("MyTable2").ImportData (oBCP)

'' ExportData 与  ImportData 有返回值,  - -
补充:VB ,  控件
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,