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

½Ð±Ð¦³ÃöADODB.STREAM©MMicrosoft.XMLHTTPªº¥Îªk

#10 ªº¼gªk¡A¥u¯à¬Ù¤@­Ó¨BÆJ...

Ū¨ú¸ê®Æ > Àx¦s¦¨CSV >  (¥i¬Ù²¤)Ū¨úCSV(¥i¬Ù²¤) > CSVª½±µ¼g¤JACCESS > §R°£CSVªº¹Lµ{[code]
diabo

TOP

§¹¾ãµ{¦¡½X....
  1. Sub ±NCSVÀɸê®Æ¼g¤JACCESS()

  2.      Dim cn As ADODB.Connection
  3.    
  4.     '«Ø¥ßADODB Connectionª«¥óÅܼÆ
  5.      Set cn = New ADODB.Connection
  6.    
  7.      TARGET_DB = "TaiwanDB.mdb"
  8.      tbl = "PRICE_Daily"
  9.      ªÑ²¼¥N¸¹ = "1101"
  10.      theCsvFolder = ThisWorkbook.Path
  11.    
  12.     '«Ø¥ßACCESS(*.mdb)³sµ²
  13.      cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  14.              "Data Source=" & ThisWorkbook.Path & "\" & TARGET_DB & ";" & _
  15.              "Persist Security Info=False"
  16.          
  17.      strFields = "[Date],[Open],[High],[Low],[Close],[Volume],[Adj Close] as [AdjClose]"
  18.      strSQL = "INSERT INTO [" & tbl & "] SELECT " & ªÑ²¼¥N¸¹ & " as [StockID]," & strFields & " FROM [Text;Database=" & theCsvFolder & "].[" & ªÑ²¼¥N¸¹ & "#CSV]"

  19.     '°õ¦æSQL command
  20.      cn.Execute strSQL
  21.      
  22.     'Ãö³¬ADODB connection
  23.      cn.Close
  24.      
  25.     '²M°£¦û¥Î°O¾ÐÅé
  26.      Set cn = Nothing

  27. End Sub
½Æ»s¥N½X
diabo

TOP

³o­Ó¤èªk¦n¹³¤£¿ù¡A«Ý§Ú¦^®a§ï¦¨³o­Ó¸Õ¸Õ¡AÁÂÁÂ

TOP

¦^´_  ¤p«L«È
§A¤w¦³¿n¤À44¤À  ª©³W: Àɮתþ¥ó­­µ¥¯Å¤¤¾Ç¥Í¡]¿n¤À50¡^¥H¤W¤~¯à¤U¸ü
¥[ªo ¥[ªo!
GBKEE µoªí©ó 2012-8-31 10:24



    ²×©ó¦¨¬°¤¤¾Ç¥Í¤F¡A¥i¥H¸üªþ¥ó¤F
¤Ó§Q®`¤F¡A­ì¨Ó¥i¥H³o¼Ë²¤Æªº¡AÁÂÁ¡I¤º®e¤Ó¦h¡A­nÂI®É¶¡®ø¤Æ

¦ý¥i¥H¦h¤F¸Ñ¤@¤U¡A¥ÎDAO ©MADODB¦b°õ¦æ®Ä²v¤W¦³¨S¦³¤À§O¡H
¦]¬°DAO¤£¥Î¹³ADODB­n¼gprovider=?????¡A®e©ö°O¦í¡C

¥t¥~¡A§Ú¬Ý¨ì¡u¸ê®Æ¾É¤J¸ê®Æ®w()¡v¤¤¡A§A¬O¥ÎFOR LOOP+.AddNew +.UPDATEªº¤èªk¼g¤J¸ê®Æ¡A³o­Ó©M¥ÎSQL COMMANDªºINSERT¡A¦b°õ¦æ³t«×¤W¦³¨S¦³¤À§O¡HÁÂÁÂ

TOP

¦^´_  ¤p«L«È
¸Õ¸Õ¬Ý
GBKEE µoªí©ó 2012-8-30 16:21



    §Ú­è­è¸Õ¤ñ¸û¥Î.ADDNEW©M.UPDATE©MSQL INSERT ³t«×¤ñ¸û¡A§Úµo²{¥ÎSQL INSERT¤ñ«eªÌ§Ö«Ü¦h
  1. Set wb = Workbooks.Open(myUrl)
  2.         With myRS
  3.             For Each a In ActiveSheet.Range([A2], [A2].End(xlDown))
  4.                 .AddNew        '²K¥[¦U­ÓÄæ¦ìªº¸ê®Æ
  5.                 For i = 1 To .Fields.Count - 1
  6.                     .Fields(0) = shareNo
  7.                     .Fields(i) = a(1, i)
  8.                 Next i
  9.                 .Update       '§ó·s¸ê®Æªí
  10.             Next
  11.         End With
½Æ»s¥N½X
©Ò¥H§Ú§Æ±æ¥ÎSQL§@¸ê®Æ¼g¤J¡A¦ý½Ð°Ý³o¥y¦p¦ó§ï¼g¦¨¥Î wb ©Îactivebook§@DATABASE©O¡H
  1. "insert into Price select * from (select " & shareNo & " as Share, Date, Open, High, Low, Close, Volume as Vol, [Adj Close] as AClose from [Excel 8.0;hdr=yes;imex=1;Database=" & wb & "].[table$A1:G" & r & "])"
½Æ»s¥N½X
ÁÂÁ«ü±Ð

TOP

        ÀR«ä¦Û¦b : ¹D¼w¬O´£ª@¦Û§Úªº©ú¿O¡A¤£¸Ó¬O¨þ¥¸§O¤HªºÃ@¤l¡C
ªð¦^¦Cªí ¤W¤@¥DÃD