发新话题
打印

[转载]执行SQL脚本文件.sql的两种方法

[转载]执行SQL脚本文件.sql的两种方法

  信息来源:blog.yesky.com(这个地方转人家的文章从来不写来源 鄙视)

1.
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

2.
Public Sub ExecuteSQLScriptFile(cn as ADODB.Connection,sqlFile As String)
Dim sql as string

     sql="master.dbo.xp_cmdshell &#39; osql -U username -P password -i " & sqlFile
     cn.execute sql
End Sub
曾几何时,有人对我说:装B遭雷劈。我说:去你妈的。于是,这个人又对我说:如果再说脏话,上帝会惩罚你的。我说:我操上帝。结论:彪悍的人生不需要上帝。

TOP

发新话题