我听有人说是通过Sqlserver中的导出接口,可就是不明白,请高手指点

解决方案 »

  1.   

    /** 导出文本文件
    EXEC master..xp_cmdshell 'bcp "dbname..tablename" out c:\DT.txt -c -Sservername -Usa -Ppassword'

    EXEC master..xp_cmdshell 'bcp "Select * from dbname..tablename" queryout c:\DT.txt -c -Sservername -Usa -Ppassword'导出到TXT文本,用逗号分开
    exec master..xp_cmdshell 'bcp "库名..表名" out "d:\tt.txt" -c -t , -U sa -P password'
    BULK INSERT 库名..表名
    FROM 'c:\test.txt'
    WITH (
        FIELDTERMINATOR = ';',
        ROWTERMINATOR = '\n'
    )
      

  2.   

    这样虽然可以导过sql查询分析器进行导出,可是在vb程序中却无法加以控制。
    有什么好的方法可以用vb进行导出?
    这样就可以方便用户了。
      

  3.   

    我是先装数据装入界面,再导出,我用的是spread2.5控件,仅供参考
    '导出数据
    Private Sub cmdOutData_Click()
        On Error GoTo ErrH
        Dim nFileName As String, nTitle As String, nLine As String
        Dim nResponse As Long, i As Integer, j As Integer
        
        '定义默认文件名
        nFileName = mTableName
        
        '定义对话框默认属性
        dlg.CancelError = True '可以捕获按下cancel按钮
        dlg.FileName = nFileName & ".txt"
        dlg.DialogTitle = "保存数据"
        dlg.Filter = "文本文档(*.txt)|*.txt|所有文件(*.*)|*.*"
        dlg.ShowSave
        nFileName = dlg.FileName
        
        '判断文件是否存在
        If Dir(nFileName) <> "" Then
            nResponse = MsgBox("该文件已存在,是否覆盖?", vbOKCancel Or vbInformation, "信息")
            If nResponse = vbKeyCancel Then Exit Sub
        End If
        
        
        '写入文件
        Open nFileName For Output As #1
        '获取标题
        spdList.Row = 0
        For i = 1 To spdList.MaxCols
            spdList.Col = i
            nTitle = nTitle & spdList.Text & vbTab
        Next i
        nTitle = nTitle & vbCrLf
        Print #1, nTitle
        
        '获取表格中的内容
        For i = 1 To spdList.DataRowCnt      '获取每一行
            nLine = ""
            For j = 1 To spdList.MaxCols
                nLine = nLine & CellGetValue(spdList, i, j) & vbTab
            Next j
            Print #1, nLine
        Next i
        
        Close #1
        Exit SubErrH:
        Exit Sub
    End Sub