关于用vb来实现sql数据库里面的表,转换成excel文件的程序,不能运行,急等待
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