关于用vb来实现sql数据库里面的表,转换成excel文件的程序,不能运行,急等待

chenminer 2003-11-21 02:58:20
Dim cn As New ADODB.Connection
Dim ServerName As String
Dim UserName As String
Dim Password As String
Dim connstring As String

Dim rs As ADODB.Recordset

' Put text box values into connection variables.
ServerName = txtservername.Text
UserName = txtUserName.Text
Password = txtPassword.Text

On Error GoTo ErrHandler:
connstring = "provider=SQLOLEDB.1;Persist Security Info=True;Data Source=" & ServerName & ";Initial catalog=" & cmbDatabaseName.Text & ";User ID=" & UserName & ";password=" & Password

Set cn = New ADODB.Connection
cn.Open connstring

Set rs = cn.Execute("master..xp_cmdshell 'bcp " & cmbDatabaseName.Text & ".dbo." & Cmbtablename.Text & " out " & txtDataFileName.Text & " -c -q -S" & Chr$(34) & txtservername.Text & Chr$(34) & " -U" & Chr$(34) & txtUserName.Text & Chr$(34) & " -P" & Chr$(34) & txtPassword.Text & Chr$(34) & "'")



cn.Close
Set cn = Nothing
ErrHandler:
MsgBox "Error " & Err.Description
Exit Sub
...全文
35 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenminer 2003-11-21
  • 打赏
  • 举报
回复
但是现在主要问题是,不在目录下面生成。XLS文件
饮水需思源 2003-11-21
  • 打赏
  • 举报
回复
cn.Close
Set cn = Nothing
exit sub '---------->这里少了退出语句
ErrHandler:
MsgBox "Error " & Err.Description
Exit Sub
lemonchen 2003-11-21
  • 打赏
  • 举报
回复
什么错误?
chenminer 2003-11-21
  • 打赏
  • 举报
回复
有人吗
等待

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧