Excel宏操作SQL数据库

发布网友 发布时间:2022-04-23 02:54

我来回答

1个回答

热心网友 时间:2023-10-12 11:21

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strCn As String
Dim strSQL As String

Dim CountryCode As String
Dim CountryName As String
Dim DeleteFlg As String
Dim CreateBy As String
Dim UpdateBy As String

'strCn = "Provider=sqloledb;Server=xxxx;Database=xxxx;Uid=sa;Pwd=sa;"
strCn = strConn
'MsgBox strCn
'open connect
cn.Open strCn

'**********************************************
strSQL = "DELETE FROM xxxx"
cn.Execute strSQL

cn.Close

'get the max row number
Dim RowCount As Integer
RowCount = Sheet3.UsedRange.Rows.Count

'get the time
Dim nowtime As Date
nowtime = Now()
'MsgBox nowtime
Dim index As Integer
For index = 0 To RowCount
'get data from excel
111= Cells(index, 1).Value
2222= Cells(index, 2).Value
DeleteFlg = "0"
3333= Cells(index, 3).Value
4444= Cells(index, 4).Value

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com