'方法一
Public Sub ExecuteSQLScriptFile(cn as ADODB.Connection,sqlFile As String)
Dim strSql As String, strTmp As String
Open sqlFile For Input As #1
strSql = ""
Do While Not EOF(1)
Line Input #1, strTmp
If UCase$(strTmp) = "GO" Then
cn.Execute strSql
strSql = ""
Else
strSql = strSql & strTmp & vbCrLf
End If
Loop
If strSql <> "" Then cn.Execute strSql
Close #1
End Sub
'方法二
Public Sub ExecuteSQLScriptFile(cn as ADODB.Connection,sqlFile As String)
Dim sql as string
sql="master.dbo.xp_cmdshell ' osql -U username -P password -i " & sqlFile
cn.execute sql
End Sub
Public Sub ExecuteSQLScriptFile(cn as ADODB.Connection,sqlFile As String)
Dim strSql As String, strTmp As String
Open sqlFile For Input As #1
strSql = ""
Do While Not EOF(1)
Line Input #1, strTmp
If UCase$(strTmp) = "GO" Then
cn.Execute strSql
strSql = ""
Else
strSql = strSql & strTmp & vbCrLf
End If
Loop
If strSql <> "" Then cn.Execute strSql
Close #1
End Sub
'方法二
Public Sub ExecuteSQLScriptFile(cn as ADODB.Connection,sqlFile As String)
Dim sql as string
sql="master.dbo.xp_cmdshell ' osql -U username -P password -i " & sqlFile
cn.execute sql
End Sub