Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > ADP及SQL SERVER

执行SQL脚本文件(.sql)的两种方法.doc

时 间:2012-05-12 14:01:43
作 者:赵文斌   ID:4506  城市:深圳
摘 要:实用
正 文:

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



Access软件网官方交流QQ群 (群号:483923997)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助