Private Sub insert1_click()
Dim iCount As Integer
Dim cn
Set cn = CreateObject("ADODB.Connection")
cn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=8233;Initial Catalog=hskmis;Data Source=127.0.0.1"
cn.Open
cn.Execute ("delete temp9")
'计算该表有多少行
RowCount = Worksheets("FC").UsedRange.Rows.Count
'行循环
For irow = 1 To RowCount
strRecord = ""
'列循环,假设有五列,从第一列开始
For icol = 1 To 5
If icol <> 5 Then
strRecord = strRecord & "'" & Worksheets("FC").Cells(irow, icol).Value & "'" & ","
Else
strRecord = strRecord & "'" & Worksheets("FC").Cells(irow, icol).Value & "'"
End If
Next
MsgBox strRecord
Sql = cn.Execute("insert into temp9 values(" & strRecord & ")")
Next
MsgBox "插入完成"
End Sub