Excel宏操作SQL数据库

我想用Excel宏编写代码来对SQL数据进行连接和操作,请教详细的步骤或方法,重分!!!!一定加分

第1个回答  2010-05-25
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
相似回答