批量执行insert 发生错误时如何获取错误信息

xianli5 2010-10-15 05:01:26
开发过程中遇到代码如下:

Private Sub Command1_Click()

On Error GoTo errhan:

Dim sql As String

Dim conn As ADODB.Connection
Dim rsJs As ADODB.Recordset

Set conn = New ADODB.Connection

sql = "insert xl_t1 values(50005,50005) insert xl_t1 values(3147483647,50005)"

conn.ConnectionString = "Driver={sql server};server=aaa;uid=sa;pwd=2008;database=aaaaa1"
conn.ConnectionTimeout = 30
conn.Open

conn.Execute ("delete XLt_t1")
Set rsJs = conn.Execute(sql)
conn.Close

Exit Sub

errhan:
MsgBox Err.Source & "@@@@@@@" & Err.Description

End Sub

应该是第二句插入语句出错,但是该代码执行后,没有接到返回的错误信息。
是什么原因呢?

求教,要如何处理该种情况??


...全文
45 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
worldy 2013-05-31
LZ的sql语法应该不对吧 插入: conn.execute "insert xl_t1 values(50005,50005) conn.execute "insert xl_t1 values(3147483647,50005)" 删除: conn.Execute ("delete * FROM XLt_t1")
回复
benxiaohai529 2013-05-31
SQL语句间用";"号分隔
回复
饮水需思源 2010-10-16
conn.ConnectionString = "Driver={sql server};server=aaa;uid=sa;pwd=2008;database=aaaaa1"
conn.ConnectionTimeout = 30
conn.Open

conn.execute "delete from x1_t1"
conn.execute "insert into xl_t1 values(50005,50005)"
conn.execute "insert into xl_t1 values(3147483647,50005)"
回复
贝隆 2010-10-15
Private Sub Command1_Click()

On Error GoTo errhan:

Dim sql As String

Dim conn As ADODB.Connection
Dim rsJs As ADODB.Recordset

Set conn = New ADODB.Connection

sql = "insert xl_t1 values(50005,50005) insert xl_t1 values(3147483647,50005)"

conn.ConnectionString = "Driver={sql server};server=aaa;uid=sa;pwd=2008;database=aaaaa1"
conn.ConnectionTimeout = 30
conn.Open

conn.Execute ("delete XLt_t1")
Set rsJs = conn.Execute(sql)
conn.Close

Exit Sub

errhan:
MsgBox Err.Source & "@@@@@@@" & Err.Description

End Sub

会不会是这两个不一致所致?
回复
xianli5 2010-10-15
帮忙啊,谢谢各位了
回复
相关推荐
发帖

1188

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2010-10-15 05:01
社区公告
暂无公告