- ©«¤l
- 552
- ¥DÃD
- 3
- ºëµØ
- 0
- ¿n¤À
- 578
- ÂI¦W
- 0
- §@·~¨t²Î
- win7
- ³nÅ骩¥»
- office 2010
- ¾\ŪÅv
- 50
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2015-2-8
- ³Ì«áµn¿ý
- 2024-7-9
|
¦^´_ 3# Changbanana
Àx¦s®æ¤¤¨S¦³¸ê®Æ¡A¦bVBA°}¦C¤¤¨Ã¤£·|¥H¬°¬ONullÈ
¦ÓSQL»y¨¥¤¤«h¬O¥²¶·µ¹¥LNullÈ
©Ò¥H¦barr¤¤¦³ªÅ¥Õ³B¡A¥²¶·§â¥¦§ï¦¨"Null"
©Ò¥Hn¦hÓ°j°é¥h§ó§ï¥LªºªÅÈ
INSERT INTO¬O·s¼W¸ê®Æ¡AYקïªí®æ¤¤ªº¸ê®Æ´N»Ýn¥Î¨ìUPDATE «ü¥O
¦³ÃöSQL»yªk¡A½Ð¦Û¦æGoogle "SQL"- Public Sub ¶×¥X()
- Dim arr, i%
- Dim myCon As Object, myRs As Object, sql$
- Set myCon = CreateObject("ADODB.Connection")
- Set myRs = CreateObject("ADODB.Recordset")
- myCon.Open "provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & ThisWorkbook.Path & "\test.accdb;"
- arr = Sheets(1).Range("C1", Sheets(1).[A65535].End(xlUp))
- For i = 1 To UBound(arr)
- For j = 1 To UBound(arr, 2)
- aa = arr(i, j)
- If arr(i, j) = Empty Then
- arr(i, j) = "Null"
- End If
- Next
- Next
- Set myRs = Nothing
- For i = 1 To UBound(arr)
- sql = "SELECT * FROM ¸ê®Æªí1 WHERE ¸ê®Æªí1.¦WºÙ Like '" & arr(i, 1) & "';"
- Set myRs = myCon.Execute(sql)
- If myRs.EOF = True Then
- sql = "INSERT INTO " & "¸ê®Æªí1" & "(¦WºÙ,ID,¦¨ÁZ)" & _
- " VALUES('" & arr(i, 1) & "','" & arr(i, 2) & "'," & arr(i, 3) & ");"
- Set myRs = myCon.Execute(sql)
- End If
- Set myRs = Nothing
- Next
- Set myRs = Nothing
- myCon.Close
- Set myCon = Nothing
- End Sub
½Æ»s¥N½X |
|