|
我在一个过程中,要使用多次SQL来进行插入数据的操作,
比如下面这部分代码,
Set conn = CreateObject("adodb.connection")
Set rst = CreateObject("adodb.recordset")
conn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=D:\Tony\Daily\帐本.xls"
'If MultiPage1.Value = 1 Then '如果选择了多页控件的第一页
If ComboBox22.Text = "现金" Then
With Workbooks("帐本.xls").Sheets("日常支出登记")
.Cells(1, 1) = .Cells(1, 1) + 1
sql = "insert into [日常支出登记$](索引,日期," & ComboBox1.Text & "," & ComboBox1.Text & "描述) values ('" & .Cells(1, 1) & "','" & DTPicker1.Value & "','" & TextBox1.Text & "','" & TextBox5.Text & "-" & ComboBox22.Text & "')"
conn.Execute sql
sql1 = "insert into [现金$](索引,日期,消费,消费描述) values ('" & .Cells(1, 1) & "','" & DTPicker1.Value & "','" & TextBox1.Text & "','" & TextBox5.Text & "')"
conn.Execute sql1
但是结果是只有第一个SQL语句成功执行了,第二个没有,要怎么改一下,实际情况可能要使用六七次SQL进行数据插入的操作,
代码要怎么写比较好, |
|