在VB中用SQL查询到记录集,然后把记录集导出,格式为.csv,代码怎么写呀?有没有例子 (数据库用:SQL SERVER 2000),大家帮帮忙啦.

解决方案 »

  1.   

    可以直接用ADO.RecoedSet的Save方法保存啊
    Saves (persists) the Recordset in a file. Syntaxrecordset.Save FileName, PersistFormat ParametersFileName   Optional. Complete path name of the file where the Recordset is to be saved.PersistFormat   Optional. A PersistFormatEnum value that specifies the format in which the Recordset is to be saved. Can be one of the following constants.Constant Description 
    adPersistADTG (Default) Save in proprietary Advanced Data Tablegram format. 
    adPersistXML Save in XML format. 
      

  2.   

    试试:exec master..xp_cmdshell 'bcp "库名..表名" out "d:\ret.csv" -c -t ,-U sa -P password'
      

  3.   

    用SQL+connection对象:
    strPutOutSQL = "Select * Into " & strFileName & " From " & strPutOutTable & _
                        " IN[ODBC][ODBC;Driver=SQL Server;UID=sa;PWD=" & PASSWORD & ";" & _        "Server=" & gServerIP & ";" & _
                        "DataBase=" & DATA_BASE_NAME & ";]" 
    conY.Execute strPutOutSQL但有一个问题:如果导入的数据保存路径在数据库服务器上,没有问题;但如果在客户端运行程序并从服务器导数据在客户端机子上出现问题,该问题如何解答?望经验者告知!!