ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ½sĶ¿ù»~-ADODB.Connection

[µo°Ý] ½sĶ¿ù»~-ADODB.Connection

½Ð°Ý¦³¤Hª¾¹D¬°¤°»ò¶Ü?

¬O­þ­ÓÀô¸`¨S³]©w¦n?



¤H¥Í¤£¤@©w²y²y¬O¦n²y¡A¦ý¬O¦³¾ú½mªº±j¥´ªÌ¡AÀH®É³£¥i¥H´§´Î¡C

¦^´_ 1# yifan2599


    ¤Þ¥Î¿ù»~¡I
­n¤U­±³o­Ó¡A x.x ª©¥»¦Û¿ï

Microsoft ActiveX Data Objects x.x Library

TOP

¦^´_ 1# yifan2599

¤@­Ó¼Ò«¬¶ôÅý§A¸Õ¡A¤£¥Î¤Þ¥Î¶µ¥Ø
    Dim myCon As Object, myRs As Object
    Dim arr, i%, SQL$
    arr = Sheets("¤u§@ªí3").Range("A2:B74")
    Dim myCon As ADODB.Connection '³sµ²¸ê®Æ®w
    Dim myRs As ADODB.Recordset '³sµ²¸ê®Æªí
    Set myCon = New ADODB.Connection
    myCon.Open "provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & ThisWorkbook.Path & "\Db.accdb;"
    For i = 1 To UBound(arr) ''¶}©l¶×¤J¨ì¸ê®Æ®w
        SQL = "INSERT INTO " & "³¡ªù" & "(³æ¦ì¥N¸¹,³æ¦ì¦WºÙ)" & _
        " VALUES('" & arr(i, 2) & "','" & arr(i, 1) & "')"
        Set myRs = myCon.Execute(SQL)
    Next
    myCon.Close 'Ãö³¬ myCon
    Set myRs = Nothing '³]©w myRS ¬° Nothing
    Set myCon = Nothing '³]©w myCon ¬° Nothing

TOP

¥»©«³Ì«á¥Ñ lpk187 ©ó 2016-9-5 00:45 ½s¿è

¦^´_ 1# yifan2599


    ¹ï¤£°_¡I¡I3¼Óªº¥N½X¬O­n¤Þ¥Î¤~¹ï¡A¤U«h¤~¤£¥Î¤Þ¥Î¶µ¥Ø
  1. Public Sub ex()
  2. Dim i%, arr
  3. Dim myCon As Object, myRs As Object, SQL$
  4.     arr = Sheets("¤u§@ªí3").Range("A2:B74")
  5.     Set myCon = CreateObject("ADODB.Connection")
  6.     Set myRs = CreateObject("ADODB.Recordset")
  7.     myCon.Open "provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & ThisWorkbook.Path & "\Db.accdb;"
  8.     For i = 1 To UBound(arr) ''¶}©l¶×¤J¨ì¸ê®Æ®w
  9.         SQL = "INSERT INTO " & "³¡ªù" & "(³æ¦ì¥N¸¹,³æ¦ì¦WºÙ)" & _
  10.         " VALUES('" & arr(i, 2) & "','" & arr(i, 1) & "')"
  11.         Set myRs = myCon.Execute(SQL)
  12.     Next
  13.         Set myRs = Nothing
  14.     myCon.Close
  15.     Set myCon = Nothing

  16. End Sub
½Æ»s¥N½X

TOP

¦^´_ 4# lpk187


·Q½Ð±Ð±z­Y¸ê®Æ®w¦³³]©w±K½X
  1.   myCon.Open "provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & ThisWorkbook.Path & "\Db.accdb;"
½Æ»s¥N½X
§ï¦¨
  1.   myCon.Open "provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & ThisWorkbook.Path & "\Db.accdb;"& "Jet OLEDB:Database Password=abcd;"
½Æ»s¥N½X
¦ý¬O³o¼Ë¨Ì·|¥X²{¿ù»~¦pµe­±
¹Ï¤ù1.png

·Q½Ð±Ð¬O­þÃä¥X°ÝÃD¡A³Â·Ð±z¤F

TOP

        ÀR«ä¦Û¦b : Ãø¦æ¯à¦æ¡AÃø±Ë¯à±Ë¡AÃø¬°¯à¬°¡A¤~¯àª@µØ¦Û§Úªº¤H®æ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD