|
Private Sub CommandButton1_Click()
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim i As Integer
Dim mystr As String
cnn.ConnectionString = "provider=sqloledb;" _
& "user id=生产;" _
& "password=123456;" _
& "data source=sa;" _
& "initial catalog=人力资源;"
cnn.Open
If MsgBox("确保考勤无误,可以上报办公室!是否添加?", _
vbQuestion + vbYesNo) = vbYes Then
For i = 5 To Range("b65536").End(xlUp).Row
mycolumn = "(工段,日期,工号,姓名,班组,岗位,考勤,迟到,早退,晚加班小时,病假,事假,旷工,年休,是否超晚8点)"
mystr = "values("
mystr = mystr & "'" & Cells(3, 3) & "','" & Cells(3, 6) _
& "','" & Cells(i, 2) & "','" & Cells(i, 3) & "','" & Cells(i, 4) & "','" & Cells(i, 5) & "','" & Cells(i, 6) & "','" & Cells(i, 7) & "','" & Cells(i, 8) & "','" & Cells(i, 9) & "','" & Cells(i, 10) & "','" & Cells(i, 11) & "','" & Cells(i, 12) & "','" & Cells(i, 13) & "','" & Cells(i, 14) & "')"
sql = "insert into 考勤 " & mycolumn & " " & mystr
cnn.Execute sql
Next i
MsgBox "添加成功!", vbInformation
Range("b5:n66").ClearContents
Else
MsgBox "添加取消!", vbExclamation
Range("b5:n66").ClearContents
cnn.Close
Set cnn = Nothing
End If
End Sub
这个是我从书上搬下来的,这个是批量添加,但是我还想批量修改!如何更改???
求高手
|
|