VB如何执行SQL脚本 30

Constr="Provider=Microsoft.jet.oledb.4.0;DataSource=D:\赢家\赢家系列\大赢家\Data\3Ddyj.mdb"Con... Constr = "Provider=Microsoft.jet.oledb.4.0;Data Source=D:\赢家\赢家系列\大赢家\Data\3Ddyj.mdb"
Conn.Open Constr
Conn.Execute "DELETE Issue_3D.LotteryID FROM Issue_3D WHERE (((Issue_3D.LotteryID)=50001 Or (Issue_3D.LotteryID)=50002 Or (Issue_3D.LotteryID)=50003 Or (Issue_3D.LotteryID)=50004 Or (Issue_3D.LotteryID)=50005 Or (Issue_3D.LotteryID)=50006 Or (Issue_3D.LotteryID)=50007 Or (Issue_3D.LotteryID)=50008 Or (Issue_3D.LotteryID)=50009 Or (Issue_3D.LotteryID)=50010 Or (Issue_3D.LotteryID)=50011 Or (Issue_3D.LotteryID)=50012 Or (Issue_3D.LotteryID)=50013 Or (Issue_3D.LotteryID)=50014 Or (Issue_3D.LotteryID)=50015 Or (Issue_3D.LotteryID)=50016 Or (Issue_3D.LotteryID)=50017 Or (Issue_3D.LotteryID)=50018))" '删去id=50001-50018的数据
下面要执行*.sql 脚本,脚本内容“DELETE Issue_3D.LotteryID FROM Issue_3D WHERE 。。。。。”
如何写程序?
展开
 我来答
feiyangqingyun
2008-11-12 · TA获得超过393个赞
知道小有建树答主
回答量:350
采纳率:0%
帮助的人:285万
展开全部
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 ' osql -U username -P password -i " & sqlFile
cn.execute sql
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
揭莞然H7
2008-11-12 · TA获得超过5683个赞
知道小有建树答主
回答量:893
采纳率:0%
帮助的人:663万
展开全部
Public cn As New ADODB.Connection
Public rs As New ADODB.Recordset
Dim SQL as string

cn.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;Data Source=D:\赢家\赢家系列\大赢家\Data\3Ddyj.mdb"
cn.Open

rs.CursorLocation = adUseClient
SQL = "select * from Expense"
rs.Open SQL, cn, adOpenKeyset, adLockPessimistic

-----------------------------------------

在rs.open SQL中就可执行语句!!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式