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

[µo°Ý] ½Ð°Ý§Ú¥Îexcel¥¨¶° ¥Îsql»yªk

[µo°Ý] ½Ð°Ý§Ú¥Îexcel¥¨¶° ¥Îsql»yªk

½Ð°Ý§Ú¥Îexcel¥¨¶° ¥Îsql»yªk¨ú¡£¤j¤j1217¼ÐÅÒ$l2:l39¡¤­n©ñ¦b¦P¦bA2ªº¦ì¤l¡A»yªk¦p¤U¡G
Sub get_data_with_sql()
    Set rs = CreateObject("adodb.recordset")
    rs.Open "select * form [¤j¤j1217¼ÐÅÒ$l2:l39] ", "Driver=(Microsoft Excel Driver (*.xls));dbq=C:\¤j¤j°ª¤¤1217.xls"
    Cells(2, 1).CopyFromRecordset (rs)
End Sub
·|¥X²{'OPEN'¤èªk('._recordset'ª«¥ó)¥¢±Ñ
½Ð°Ý¦U¦ì°ª¤â³o¬O­þ­Ó³¡¤À¥X°ÝÃD¤F¡C
·PÁ¡I

¦^´_ 1# Anny
1. Driver ªº¬A©·­n¥Î¤j¬A¸¹
2. from¼g¦¨form

À³¸Ó¬O
rs.Open "select * from [¤j¤j1217¼ÐÅÒ$L2:L39]", "Driver={Microsoft Excel Driver (*.xls)};dbq=C:\¤j¤j°ª¤¤1217.xls"
Alex

TOP

¤Ó·PÁ¤F¡A¯uªº¥i¥H¤F­C¡I
¥i¬O§Ú¥[¤Fwhere ¥H«á¤S¤£¦æ¤F¡C¥D­n¬O·Q±Nitm_no³o­ÓÄæ¦ì¤£¬°ªÅªº¤~copy¨ìCells(1, 1).
·|¥X²{ error "°Ñ¼Æ¤Ó¤Ö¡A¹w´Á­Ó¼Æ1"
Sub get_data_with_sql()
    Set rs = CreateObject("adodb.recordset")
    rs.Open "select * from [¤j¤j1217¼ÐÅÒ$L2:V39] where itm_no  is not null", "Driver={Microsoft Excel Driver (*.xls)};dbq=C:\Users\dsc\Documents\¤j¤j°ª¤¤1217.xls"
    Cells(1, 1).CopyFromRecordset (rs)
End Sub

TOP

¥»©«³Ì«á¥Ñ alexliou ©ó 2012-12-22 08:15 ½s¿è

¦^´_ 3# Anny
item_no is not null  ¬O­^¤å»yªk
À³¸Ó«ç»ò§ï¦¨µ{¦¡»yªk©O?
Alex

TOP

¥»©«³Ì«á¥Ñ alexliou ©ó 2012-12-22 08:45 ½s¿è

¦^´_ 3# Anny
§Ú²q´úItem_noÀ³¸Ó«üªº¬O§A©Ò·Q­n§@¬°§PÂ_¨Ì¾ÚªºÄæ¦ì¦WºÙ
¦bSQL¥y¤l¤¤ªºFrom clause ©Ò«ü©w½d³ò ªº²Ä¤@¦C¹w³]³Qµø¬°¼ÐÃD¦C (©ÎÄæ¦ì¦WºÙ)
§Ú°²³]§A§â¨C­ÓÄæ¦ìªº¼ÐÃD©ñ¦b²Ä¤@¦C
©Ò¥H¥u­n§ï¬°
rs.Open "select * form [¤j¤j1217¼ÐÅÒ$L1:V39]  where itm_no  is not null", "Driver=(Microsoft Excel Driver (*.xls));dbq=C:\¤j¤j°ª¤¤1217.xls"
´N¥i¥H¤F
Alex

TOP

[ª©¥DºÞ²z¯d¨¥]
  • HUNGCHILIN(2012-12-23 14:07): §A¥i¥H°Ñ¦Ò³o¤@½g http://forum.twbts.com/thread-277-1-2.html

§Ú±Nitem_no ªºÄæ¦ì¦WºÙ§ï¦¨ ¶µ¦¸  ´N¥i¥H¤F­C¡I(ÁöµM¤£ª¾¹D¬°¤°»ò)
·PÁÂAlex³á

TOP

        ÀR«ä¦Û¦b : ¤Hªº²´·úªø¦b«e­±¡A¥u¬Ý¨ì§O¤Hªº¯ÊÂI¡Aµ·²@¬Ý¤£¨ì¦Û¤vªº¯ÊÂI¡C
ªð¦^¦Cªí ¤W¤@¥DÃD