SELECT * 
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
  'Data Source="c:\test.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...xactions

解决方案 »

  1.   

    exec master..xp_cmdshell 'bcp "SELECT au_fname, au_lname FROM pubs..authors ORDER BY au_lname" queryout c:\stu.xls -c  -Usa -P',NO_OUTPUT
      

  2.   

    各位高手:我SQL Server2000生成的DTS Package是Visual Basic .bas文件,用来实现将数据导入Excel的功能(用简单的select * from tablename做测试),按照下面的步骤run,结果只是将一个表的字段导入到了Excel中,没有内容。查看.bas文件,里面没有写数据的代码,难道自动生成的代码,还必须进行修改吗?各位请帮忙测试一下。Running a DTS Package Saved as a Visual Basic File
    You can run a Data Transformation Services (DTS) package that has been saved by one of the DTS tools as a Microsoft® Visual Basic® file. The saved module, a Visual Basic .bas file, consists of declarations and a Sub Main and may contain other Subs called by Sub Main. The Subs contain all the logic of the DTS package.Here are the basic steps for incorporating a Visual Basic module file into a Visual Basic project and executing it on a computer running the Microsoft SQL Server™ client tools: 1.In Visual Basic, create a new Standard EXE project.
    2.On the Project menu, click References, and then select the Microsoft DTSDataPump Scripting Object Library, Microsoft DTSPackage Object Library, and Microsoft DTS Custom Tasks Object Library check boxes. 
    Not all DTS programs will require all three of these libraries. 3.On the Project menu, click Add File, and then add the Visual Basic file produced by the DTS Import/Export Wizard or DTS Designer.
    4.In the Project Explorer, select Form1 and then on the Project menu, click Remove Form1 to remove the blank form from the Project.
    5.Run the project.  
    No indication of completion will be given other than the Visual Basic Development Environment will go back to design mode.You may want to add completion notification and error handling and controls to allow the user to invoke the transformation.
      

  3.   

    save you dts files as *.dtsPrivate Sub RunPackage(ByVal S As String)'S为DTS文件名
        Dim objPackage      As DTS.Package2
        Dim objStep         As DTS.Step
        Dim objTask         As DTS.Task
        Dim objExecPkg      As DTS.ExecutePackageTask
        Set objPackage = New DTS.Package
        objPackage.FailOnError = True
        Set objStep = objPackage.Steps.New
        Set objTask = objPackage.Tasks.New("DTSExecutePackageTask")
        Set objExecPkg = objTask.CustomTask
        With objExecPkg
            .PackagePassword = ""
            .FileName = S
            .Name = "ExecPkgTask"
        End With
        With objStep
            .TaskName = objExecPkg.Name
            .Name = "ExecPkgStep"
            .ExecuteInMainThread = True
        End With
        objPackage.Steps.Add objStep
        objPackage.Tasks.Add objTask
        objPackage.Execute
        Set objExecPkg = Nothing
        Set objTask = Nothing
        Set objStep = Nothing
        Set mobjPkgEvents = Nothing
        objPackage.UnInitialize
    End Sub
      

  4.   

    以上程序是你的DTS Package不传递参数,若你的DTS Package要传递参数,
    设计时声明一下,以上程序改一下即可。
      

  5.   

    我想试一下.bas文件的用法啊!
      

  6.   

    哪位能告诉我.bas文讲怎么用啊。