Dao »P SQL »yªk½d¨Ò(¥|)

¦^­º­¶


¤ÀÃþ

¼ÐÃD

¤j·N

§@ªÌ

¤é´Á

SQL »yªk ¥¿½TªºÄæ¦ì­È¬d¸ß®æ¦¡ ¡@ ¦Ñ©Ç 1999/1/31
SQL »yªk ¨âªí¦X¨Ö¡A­ç°£­«½ÆÁä­ÈÄæ¦ì¡C ¡@ ¦Ñ©Ç 1999/1/31
SQL »yªk ²£¥Í¦Pµ²ºcªÅ¥Õ¸ê®Æªí ¡@ ¦Ñ©Ç 1999/3/7
SQL »yªk ¤é´ÁÄæ¦ì§t®É¶¡ªº¬d¸ß ¡@ ¦Ñ©Ç 1999/3/7
SQL »yªk ¿é¤J¤ë¥÷¬d¸ß¾ã¤ë©Ò¦³°O¿ý ¡@ Fumi 1999/3/7
SQL »yªk ¥Î SQL °µÄæ¦ì±Æ§Ç ORDER BY FieldName ¦Ñ©Ç 1999/4/16
SQL »yªk °ÊºA¼W´îÄæ¦ì¬d¸ß ¡@ ¦Ñ©Ç 1999/5/22
Dao ¾Þ§@ Database ªº¶}¶}ÃöÃö ¡@ ¦Ñ©Ç 1999/1/31
Dao ¾Þ§@ ¤å¦rÀɸê®Æ®w¨Ï¥Î¤§ Schema.Ini ¸Õ§@ ¡@ ¦Ñ©Ç 1999/3/12
Dao ¾Þ§@ ¦b MDB ¸ê®Æ®w¤¤Ápµ²¨ä¥L«¬ºA¸ê®Æ®w ¡@ ¦Ñ©Ç 1999/4/10
Dao ¾Þ§@ §â MDB ªº¸ê®ÆªíÂð_¨Ó Tabledef ªº Attributes Äݩʸs ¦Ñ©Ç 1999/4/23
Dao ¾Þ§@ ¥Î TreeView ®i²{¸ê®Æ®w¤§¶¥¼hµ²ºc ¡@ ¦Ñ©Ç 1999/5/8
Dao ¾Þ§@ Index ª«¥óªº¨Ï¥Î¤Î­­¨î ¡@ ¦Ñ©Ç 1999/6/7
Dao ¾Þ§@ ¨ú±oÄæ¦ìªø«×¨ÃÁקK¿é¤J¶W¹Lªø«×¸ê®Æ Field.Size ¦Ñ©Ç 1999/6/29
Dao ¾Þ§@ §ó§ï MDB ¸ê®Æ®w±K½X ¡@ ¦Ñ©Ç 1999/7/1
DBGrid ¼W¥[ Columns Äæ¦ì(DataUnBound ª¬ªp) Columns.Add ¤èªk ¦Ñ©Ç 1999/5/4
DBGrid °»´ú¨Ï¥ÎªÌ Click ªºÄæ¦ì Column.DataField ÄÝ©Ê ¦Ñ©Ç 1999/6/25
¸ê®Æ¤ÀªR MDB ¸ê®Æªí¨Æ«eÃöÁp»P¨Æ«áÃöÁp ¡@ ¦Ñ©Ç 1999/3/4
¸ê®Æ¤ÀªR MDB Äæ¦ìªº¨Æ«e¯Á¤Þ»P¨Æ«á¯Á¤Þ ¡@ ¦Ñ©Ç 1999/3/31
¸ê®Æ¤ÀªR QueryDef ¹ï Relation ©M Index ªºÄ~©Ó ¡@ ¦Ñ©Ç 1999/3/31

Dao »P SQL »yªk½d¨Ò¨Ï¥Î»¡©ú


  1. ¥»¸ê®Æ®w½d¨Ò¥u¾A¥Î Dao ª«¥ó¡A³æ¤@¨Ï¥ÎªÌªº¾Þ§@¡A¦h¨Ï¥ÎªÌ¤Îºô¸ô¤Wªº¨Ï¥Î¡A¦]¦³§ó¦hªº­­¨î¡A¥»½d¨Ò¥¼¥²¯à¥¿½T°õ¦æ¡C¥»½d¨ÒÅwªï«DÀç§Q©Ê­Ó¤H¤Î²Õ´Âà¸ü¨Ï¥Î¡AÀç§Q¤§§Q¥Î½Ð¥ý¼x±o¥»¤H¤§¦P·N¡A¨Ó«Hµù©ú¨Ï¥Î¤è¦¡¤Î¦^ÂЦa§}¡C
  2. DBGrid¡BDBCombo ÁöÄÝ VB ¥~«Ø±±¨î¶µ¡A¦ý¦]»P Dao ¸ê®Æ®w®§®§¬ÛÃö¡A©Ò¥H¤]©ñ¥»½g°Q½×¡A¦Ó¤£¥¦ÂkÃþ¦b ActiveX ¶µ¡C
  3. ¥»½d¨Ò©Ò¦³ªºµ{¦¡½X½d¨Ò¡A¬ÒÄݤQ¤À°ò¥»ªº VB »yªk¡A¦pªG±z¬O­Ó VB User ¡AÅwªïª½±µ¤Þ¥Î©Î§ï¼g¨Ï¥Î¦b§Aªºµ{¦¡¤¤ ¡A¥»¤H¤£¥D±iµÛ§@Åv¡A¦]¬°¡A¨S¿ìªk¬d¹À¡C
  4. ¦pªG§A¬O­Ó VB ªì¾ÇªÌ¡A¤S¦³ÂI½a½a(©M¦Ñ©Ç¤@¼Ë)¡A»°§Ö§â¥»­¶¥t¦s·sÀɨì§A¦Û¤vªººÏºÐ¡AÂ÷½u«áºCºC¬Ý¡A¤]¥i¥H Copy µ¹ªB¤Í³á(¤£¥i¥H¦¬¿ú)¡C
  5. ¥»½d¨Ò³£¬O¦Ñ©Ç´X­Ó¤ë¨Ó¦b tw.bbs.comp.language °Q½×¸s²Õ¤¤¦^µªª©¤Í°ÝÃDªº¦X¿è¡A¦]¬°¬O°w¹ï°ÝÃD¸Ñ¨M¡A©Ò¦³¨Ã¨S¦³¥þ­±Æ[©Àªº¸Ñ»¡¡A¤£¾A¦X§@¬°¤Jªù¤å³¹¡A¦ý¦pªG§AŪ¤F¤Jªù®Ñ¡A©Î¬O¤W¤F¦Ñ®vªº½Ò¡A¤ß¤¤¤´¤£¬Æ©ú¥Õªº¸Ü¡A´N¥i¥H¨Ó³o§ä§ä¦³¨S¦³§A­nªºµª®×¡A¦]¬°³o³£¬O§O¤H°Ý¹Lªº°ÝÃD¡C

¦^¯Á¤Þ


¥¿½TªºÄæ¦ì­È¬d¸ß®æ¦¡


  1. ·í§Ú­Ì­n°µ¸ê®ÆªíªºÄæ¦ì±ø¥ó¬d¸ß®É¡A°ò¥»ªº»yªk¬O±Ä¥Î [WHERE Äæ¦ì¦WºÙ=¯S©wÄæ¦ì­È] ³o¼Ëªº±Ô­z¡C¦p¡G
    Dim Db As Database
    Dim Rs As Recordset
    Dim SQLString As String
    Dim ParaString As String

    Set Db=OpenDataBase("¸ê®Æ®w¸ô®|¤Î¦WºÙ")
  2. ¦r¦êÄæ¦ìªº±ø¥ó¬d¸ß¡A°Ñ¼Æ¦r¦ê«e«á­n¥]§¨ ['] ¦r¤¸¡G
    ParaString="ABCD"
    SQLString="SELECT * FROM ¸ê®Æªí¦WºÙ WHERE Äæ¦ì¦WºÙ='" & ParaString & "';"
  3. ¼Æ­ÈÄæ¦ìªº±ø¥ó¬d¸ß¡A°Ñ¼Æ¦r¦ê«e«á¤£­n¥]§¨¥ô¦ó¦r¤¸¡G
    ParaString=Cstr(1234)
    SQLString="SELECT * FROM ¸ê®Æªí¦WºÙ WHERE Äæ¦ì¦WºÙ=" & ParaString & ";"
  4. ¤é´ÁÄæ¦ìªº±ø¥ó¬d¸ß¡A°Ñ¼Æ¦r¦ê«e«á­n¥]§¨ [#] ¦r¤¸¡G
    ParaString=CStr(Date())
    SQLString="SELECT * FROM ¸ê®Æªí¦WºÙ WHERE Äæ¦ì¦WºÙ=#" & ParaString & "#;"
  5. ÅÞ¿èÄæ¦ìªº±ø¥ó¬d¸ß¡A°Ñ¼Æ¦r¦ê­n§ï¦¨ "True" or "False" ¡G
    If §PÂ_¬°¯u Then
    ParaString="True"
    Else
    ParaString="False"
    End IF
    SQLString="SELECT * FROM ¸ê®Æªí¦WºÙ WHERE Äæ¦ì¦WºÙ=" & ParaString & ";"
  6. ³Ì«á°õ¦æ SQL ±Ô­z¡G
    Set Rs=Db.OpenRecordset(SQLString)
  7. ³Ì«á½Ð¦U¦ì´x´¤¤@­Ó­«ÂI¡A¤£ºÞ³Q¬d¸ßÄæ¦ì¬°¦óºØ«¬ºA¡A³Ì«á§Î¦¨ SQLString ªº ParaString ¤@©w­nÂন¦r¦ê¡A¦A¨Ì³Q¬d¸ßÄæ¦ì«¬ºA¨M©w±Ä¥Î¦óºØ¥]§¨¦r¤¸¡A©Îª½±µ§ï¦¨ "True","False"¡C

¦^¯Á¤Þ


Database ªº¶}¶}ÃöÃö


ÅKµ¡¤E¤­¤§¤ñº¸·R´þ ¼¶¼g©ó¤å³¹

½Ð°Ý¥HVB¨Ó§ìMDBÀÉ¡A¦pªG¥HDATAª«¥ó¤è¦¡¨ÓÂ^¨ú¸ê®Æ¡A¦b§Ú¤U¤FDATA1.RECORDSET.CLOSE¤ÎDATA1.DATABASE.CLOSE«á¡A¬O§_ÁÙ¸ò¸ê®Æ®w³s¦b¤@°_¡A¦Ó¼vÅT¨ì¨ä¥LUSERªº¨Ï¥Î¡C

¦Ñ©Çµª¡G

­ì«h¤W¤w²æÂ÷³sµ²¡A§Þ³N¤W§A«o«Ü¥i¯àÅý¥¦¤S³s¤W¡A¦¹¸Ü«çÁ¿¡A½Ð¬Ý¤U¨Ò¡G

Private Sub Command1_Click()
    Data1.Recordset.Close
    Data1.Database.Close

    '**Data1.Refresh**
    DBGrid1.Refresh
End Sub

§A§â¥´¬P¸¹ªº¨º¦æ¥ýµù°OÅý¥¦¥¢¯à¡A¨º»ò§Aµoı Command1 Click «á¡AªGµM¨ä¥Lµ{¦¡¥i¥H¶}¦P¤@ÀɮסA¦ý¦pªG§A§â¬P¸¹¨º¬q´_¯à¡A¨º§A·|µoı¡ACommand1 ±Ô­z¦n¹³¤@ÂI§@¥Î³£¨S¦³¡C¨ä¹ê Data1 ¬O¦³Ãö¤F Recordset ©M Database ¡A¥u¬O¦b Refresh ±Ô­z«á¡A¥¦¤S§â§A¦b³]­p¶¥¬q³]©wªº¸ê®Æ­«¶}¤F¤@¦¸¡Aµ²ªGÁÙ¬O¨SÃö±¼¡CSo¡Aª¾¹D«ç»ò¦^¨Æ¤F¶Ü¡C

¦^¯Á¤Þ


¨âªí¦X¨Ö¡A­ç°£­«½ÆÁä­ÈÄæ¦ì¡C


­ü..... ¼¶¼g©ó¤å³¹

§Ú¦³¤G­Ó¸ê®Æ®wA,B¡AA¬O¥D¹q¸£¤Wªº¸ê®Æ®w,B¬O¥t¤@¹q¸£¤Wªº¸ê®Æ®w¡A²{¦b§Ú·Q§âB¦X¨Ö¨ìA¡A¦ý¬O­n­ç°£­«ÂÐÁä­Èªº¸ê®Æ¡A·Q°Ý¤@¤U¬O§_SQL¥i¥H°µ¨ì!

¦Ñ©Çµª¡G

  1. §Ú­Ì°²³]­n§â Add Table(B) ¦X¨Ö¨ì Mix Table(A) ùØ¡A¦Ó§Aªº RelationShip Key Name ¥s"½s¸¹"¡C
  2. §A¥ý¦b Add Table ¥[­Ó Yes/No ªºÄæ¦ì¡A°²³] Field.Name= Àˬd¡C
  3. §A¥ý¥Î Database.CreatQueryDef ªº¤èªk¥[¤J¦W¬° Union ªº QueryDef¡A¥h³s±µ Add ©M Mix ¨â­Ó Table ¡A¨ÃÅã¥Ü ½s¸¹Äæ¦ì¦P­Èªº°O¿ý¡G
    Dim SQLString As String, QdName As String

        QdName = "Union"
        SQLString = "SELECT Mix.½s¸¹, Add.Àˬd " _
                & "FROM Mix INNER JOIN [Add] ON Mix.½s¸¹ = Add.½s¸¹;"

        Set Qd = Db.CreateQueryDef(QdName, SQLString)

    ªþ¡G¥H«á¼W¥[ QueryDef ³£±Ä¦¹¤è¦¡¡A¤£¦A­«½Æ¡C
  4. §Q¥Î­è¤~°µ¦nªº Union ·s¼W¤@§ó·s¬d¸ß Change Query¡A¥Øªº¬O§â Add Table ùØ»P Mix ¬Û¦P°O¿ý¥Î Àˬd³o­ÓÄæ¦ì¥´¤W°O¸¹¡G
    QdName = "Change"
    SQLString = "UPDATE [Union] SET [Union].Àˬd = True;"
    ª`·N°µ¦n«á­nQd.Execut ¤@¦¸¡C
  5. ¥Î³Q¥[¹L°O¸¹ªº Add Table °µ¿ï¨ú¬d¸ß Choice Query¡G
    QdName = "Choice"
    SQLString = "SELECT Add.Field1, Add.Field2,......... " _
    & "FROM [Add] WHERE (((Add.Àˬd)=False));"
    §â Add Table °£¤FÀˬdÄæ¦ì¥~¡A©Ò¦³¨ä¥LÄæ¦ì¸ê®Æ¥[¶i¨Ó¡AÀˬdÄæ¦ì¥u¥Î°µ¿ï¨ú±ø¥ó¡A¿ï¨ú¨º¨Ç½s¸¹­È¥¼¦b Mix Table ¥X²{ªº°O¿ý¡C
  6. §Q¥Î Choice °µ³Ì«áªº·s¼W¬d¸ß AddRec Query¡G
    QdName = "AddRec"
    SQLString = "INSERT INTO Mix SELECT * FROM Choice;"
    °µ¦n«á Qd.Execute ¤@¦¸¡A«h¤@¤Á¤j¥\§i¦¨¡C
  7. ³o¨Ç QueryDef ¯d¦b§A¸ê®Æ®wùؤ£­n§R°£¡A¥H«á Add Table ¦A¦³·s¼W®É¡A§A¥u¶·¦A°õ¦æ Change Query ¤Î AddRec Query §Y¥i¡C
  8. ³o¬O¥R¤À§Q¥Î SQL ªº¤èªk¡AÀôÀô¬Û¦©¡A¨º¤@¬q¿ù¤F³Ì«á³£¤£·|¦³¥¿½Tµ²ªG¡A§A¦Û¤v¸Õ¤@¤U¡AÀ³¸Ó¥i¥H¬Ý¥X¨C¤@¨BÆJªº§@¥Î¡C

¦^¯Á¤Þ


MDB ¸ê®Æªí¨Æ«eÃöÁp»P¨Æ«áÃöÁp


¤£®¢©ó°Ý ¼¶¼g©ó¤å³¹

½Ð°ÝaccessªºÃöÁp¬O¦]¬°«Ø¥ß¬d¸ß(or from)»Ý­n®É¤~¨Ì»Ý­n³]©wÁÙ¬O,¥²¶·±N¦U­ÓÃöÁp¥þ³¡¥ý±µ³s°_¨Ó???

¦Ñ©Çµª¡G

  1. ¨âªÌ¬Ò¥i¡A¦ý«o¦³¥\¯à¤Wªº®t§O¡C
  2. MDB ¸ê®Æ®wªº¸ê®ÆªíÃöÁp¦³¨âºØ¡G

¦^¯Á¤Þ


MDB Äæ¦ìªº¨Æ«e¯Á¤Þ»P¨Æ«á¯Á¤Þ


  1. ³o°ÝÃDªºµª®×¨ä¹ê©M«e½gÃöÁp°ÝÃD¤@¼Ë¡C
  2. MDB ¸ê®Æ®wªºÄæ¦ì¯Á¤Þ¦³¨âºØ¡G

¦^¯Á¤Þ


QueryDef ¹ï Relation ©M Index ªºÄ~©Ó


  1. ©Ò¿×ªº QueryDef ¹ï Relation ©M Index ªºÄ~©Ó¡A¬O«ü¦pªG§Ú­Ì¦b MDB ¸ê®Æ®w¤¤¡A´¿°w¹ï SQL ±Ô­z©Ò³s±µªº¸ê®Æªí¨Æ¥ý°µ¹L Relation or Index ¡A¨º»ò Relation or Index ªº³]©w±N¹ï¥Ñ SQL ±Ô­z¨ú¥Xªº Recordset ²£¥Í¤°»ò¼Ëªº¼vÅT¡C
  2. ´N Index ¨Ó»¡¡G
  3. ´N Relation ¨Ó»¡¡G

¦^¯Á¤Þ


²£¥Í¦Pµ²ºcªÅ¥Õ¸ê®Æªí


·Q­n½ö¦b©p¨­Ãä ¼¶¼g©ó¤å³¹

¦p¦ó«Ø¤@­Ó©M­ì¦³¸ê®ÆªíÄæ¦ì¬Û¦PªºªÅ¥Õ¸ê®Æªí¡C

¦Ñ©Çµª¡G

¤@­Ó³Ì²³æªº¿ìªk¡A¥Î²£¥Í¸ê®Æªí Query °t¦X±ø¥ó±Ô­z¡A¨Ó·s¼W¤@¸ê®Æªí¡A¦p¡G
SQLString="SELECT OldTable.* INTO NewTable FROM [OldTable] " _ &
"WHERE (((OldTable.SomeField)="¤@­Ó¤£¥i¯à¥X²{ªº­È"));"

¦^¯Á¤Þ


¤å¦rÀɸê®Æ®w¨Ï¥Î¤§ Schema.Ini ¸Õ§@


¼s¹F·s¤@ ¼¶¼g©ó¤å³¹

½Ð°Ý ~~§Ú­n±N¤U¦CªºtextÀÉ©ñ¶i..VBªºDBGrid¤¤ªº¸Ü,Schema.ini¸Ó¦p¦ó³]£z?
11112222223333333    444444
11112222223333333    444444
11112222223333333    444444
§Ú·Q­n¤À§O±N 1111 and 222222 and 3333333 and 444444¤À§O©ñ¦bDBGrid,§Ú¸Ó«ç»ò°µ§r?

¦Ñ©Çµª¡G

  1. ¤@¯ë±Ä¥Î¼Ð·Ç CSV ®æ¦¡¯Â¤å¦rÀÉ¡A¦p¡G
    "½s¸¹","¦WºÙ","ÁʶR¤é´Á"
    1,"¬~¾vºë",1999-02-03
    2,"­»¤ô",1999-03-10
    3,"徻o",1999-03-12
    «h¥i¥Hª½±µ¥H Dao ª«¥ó¶}±Ò¡A¤£»Ý­n¤å¦rÀɸê®Æ®w¥Ø¿ý¤¤©ñ¸m Schema.Ini
  2. ²¦³º¥Ñ§OªºÀ³¥Î³nÅé²£¥Íªº¯Â¤å¦rÀÉ¥¼¥²·|¦p CSV ®æ¦¡¯ë±Æ¦C¾ã»ô¡A¦Ó¥B CSV ®æ¦¡°£¤å¦r¡B¼Æ¦r¤Î¤é´Á«¬ºA¦b Dao ùØÂà´«µL»~¥~¡A¨ä¥L«¬ºAÄæ¦ì«h¦h·|µø¬°¦r¦ê«¬ºA¡C©Ò¥H¦pªG§Aªº¤å¦rÀɮ榡¨S¦³©ú½Tªº¤À¹j²Å¸¹©Î«¬ºA¸û½ÆÂø¡A«h¥²¶·»s§@ Schema.Ini ÀÉ©ñ¦b¤å¦rÀɦP¤@¥Ø¿ý¡A¤è¯à¥H¥¿½TÄæ¦ìµ²ºcŪ¨ú¯Â¤å¦rÀɸê®Æ®w¡C
  3. ¥H¤U°w¹ï·s¤@­n¨D»s§@¬Û¦Xªº Schema.Ini ¡AÄæ¦ì¤À¹j±Ä©T©wªø«×¦Ó«D¤À¹j¦r¤¸¡C
    '-------------------------
    TextData:Sample.txt
    '-------------------------------------------------------------------------------------------
    11112222223333333    444444
    11112222223333333    444444
    11112222223333333    444444
    '---------------
    Schema.ini:
    '---------------------------------------------------------------------------------------------
    [Sample.txt]                                    '¸ê®ÆÀɦWºÙ
    Format=FixedLength                        'Äæ¦ì®æ¦¡¬°©T©wªø«×
    ColNameHeader=False                    '¤£­n¥Î²Ä¤@µ§°O¿ý°µÄæ¦ì¦WºÙ
    MaxScanRows=0                            '§ì¨úÀɮשҦ³°O¿ý
    CharacterSet=OEM                        '¦r¤¸¶°¿ï¾Ü
    Col1=Item1 Text Width 4                'Äæ¦W¤Î¼e«×³]©w
    Col2=Item2 Text Width 6
    Col3=Item3 Text Width 11
    Col4=Item4 Text Width 6
    '----------------
    VB Code:
    '----------------------------------------------------------------------------------------
    Option Explicit

    Dim Db As Database
    Dim Rs As Recordset

    Private Sub Form_Load()
        Set Db = OpenDatabase("Sample.txt ªº¸ô®|", False, False, "Text;")
        Set Rs = Db.OpenRecordset("sample")
        Set Data1.Recordset = Rs
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
        Rs.Close
        Db.Close
    End Sub
  4. ¦¹¥~»Ý°O±o¤U¦C­nÂI¡G

¦^¯Á¤Þ


¤é´ÁÄæ¦ì§t®É¶¡ªº¬d¸ß


°±¤U¸}¨B ¥ð®§¤@¤U ¼¶¼g©ó¤å³¹

¦³¤@­Ótable¥s SaleRecord¡A¦bSaleRecord¤¤¦³¤@­ÓÄæ¦ì¥s SaleTime¡A>³o­ÓSaleTimeªº«¬§O¬O datetime °O¿ýµÛ®É¶¡©M¤é´Á¡A°²¦p§Ú­n¼g¤@­ÓSQL«ü¥O§ä¥X¬Y¤Ñ¬Y®É(¨Ò¦p: 1999¦~1¤ë12¤é12:00)¥H«eªº¸ê®Æ¡A½Ð°Ý¸Ó«ç»ò¼g?

¦Ñ©Çµª¡G

Dim Db As Database
Dim Rs As Recordset
Dim SQLString As String

Set Db=OpenDatabase("Market")
SQLString="SELECT * FROM SaleRecord " & _
"WHERE SaleRecord.SaleTime < #1999/1/12 12:00:00# ;"
Set Rs =Db.OpenRecordset(SQLSTring)

¦^¯Á¤Þ


¿é¤J¤ë¥÷¬d¸ß¾ã¤ë©Ò¦³°O¿ý


'«Å§iªº³¡¤À¦p¤U:
Dim Db As Database
Dim Qd As QueryDef
Dim Rs As Recordset
Dim prmBeginDate As Parameter
Dim prmEndDate As Parameter
Set Db = OpenDatabase("Nwind.mdb")
Set Qd = Db.CreateQueryDef("", _
    "PARAMETERS BeginDate DateTime, EndDate DateTime; " & _
    "SELECT * FROM Orders " & _
    "WHERE ShippedDate>=[BeginDate] AND ShippedDate<[EndDate]")
' Bind Parameter
Set prmBeginDate = Qd.Parameters("BeginDate")
Set prmEndDate = Qd.Parameters("EndDate")

'°õ¦æ¬d¸ßªº³¡¤À¦p¤U:
Dim QueryDate As Date
QueryDate = CDate("1994/08/10")
prmBeginDate = DateSerial(Year(QueryDate), Month(QueryDate), 1)
prmEndDate = DateSerial(Year(QueryDate), Month(QueryDate) + 1, 1)
Set Rs = Qd.OpenRecordset(dbOpenDynaset)
Do Until Rs.EOF
    ' Do something here
    Rs.MoveNext
Loop

¦^¯Á¤Þ


¦b MDB ¸ê®Æ®w¤¤Ápµ²¨ä¥L«¬ºA¸ê®Æ®w


¥H¤U¥H DBF «¬ºA¸ê®Æ®w¬°¨Ò¡A¥Î Dao ª«¥ó¹ï©ó¤j«¬«D Jet MDB ¸ê®Æ®w¥i±Ä¥Î¥ý³sµ²¦A¬d¸ßªº¤è¦¡¡A½d¨Ò¦p¤U¡G
Dim Db As DataBase
Dim Td As TableDef
Dim Rs As Recordset

Set Db=OpenDatabase("§A­n»P DBF Àɳs±µªº MDB ¸ê®Æ®w")

'¦b­nÀx¦s³sµ²ªº¸ê®Æ®w¤¤«Ø¥ß¤@­Ó·sªº TableDef ª«¥ó¡C
Set Td = Db.CreateTableDef("¬°³s±µªí¨ú­Ó¦W¦r,Ä´¦p [OfficeTd]")

'³]©w©Ò­n³s½uªº¸ê®Æ®wªº«¬ºA¥H¤Î¸ê®Æ¨Ó·½ªº¦ì¸m¡C(­n¥ý½T©w§A DBF Àɮ榡)
Td.Connect = "dBASE III(or dBASE IV or dBASE 5.0);DATABASE=\\Sales\Regional\Region1"

'±N SourceTableName ³]©w¬°·Q­n¦s¨úªº DBF ÀɦWºÙ¡C
Td.SourceTableName = "Q1Sales"

'±N TableDef ·s¼W¨ì TableDefs ¶°¦Xª«¥ó¤¤¡C
Db.TableDefs.Append Td

'¥H¤W§¹¦¨ MDB »P DBF Connect

'¥Î SQL ±Ô­z¶}±Ò³sµ²¸ê®Æªíªº Recordset¡C
Set Rs = Db.OpenRecordset ("SELECT * FROM OfficeTd WHERE Office='§A­n¬d¸ßªº
¤º®e';")

'§â Recordset ¥á¨ì DataControl ¦A§Q¥Î
Set Data.Recordset=Rs

¦^¯Á¤Þ


¥Î SQL °µÄæ¦ì±Æ§Ç


¬Y ¼¶¼g©ó¤å³¹

§Úªº¸ê®Æ®w¤¤¦³¤@­Ó®É¬qªºÄæ¦ì¡A¬O¤å¦r«¬ºA  ¦p00~01¡A 02~03  ¦U¥Nªí¤@­Ó®É¬q¡A§Ú¦b·s¼W¨ì¸ê®Æªí®É¡A¦p¦óÅý¨ä«ö®É¬q¨Ó±Æ§Ç¡H

¦Ñ©Çµª¡G

SQLString="SELECT * FROM YourTableName ORDER BY ®É¬qÄæ¦ì¦W;"

¦^¯Á¤Þ


§â MDB ªº¸ê®ÆªíÂð_¨Ó


§A¤j·§¤£ª¾¹D MDB ¸ê®Æ®w¥i¥H³o»òª±¡A¨º´N¬O¦b Access ¤¤¡A¥i¥HÅý¾ã±i Table Âð_¨Ó¡A©Ò¥H§A¥i¥H§â¨Ï¥ÎªÌ±K½X³]©wªº¨º±i¸ê®Æªí³]©w¥¦ªº Hidden ÄÝ©Ê¡AÅý¥Î Access ³nÅ餣Åã¥Ü¥X¨Ó¡A¦ý¦b VB µ{¦¡ùؤ´¥i¥H¥[¥H¾Þ§@¡A½d¨Ò¦p¤U¡G

Option Explicit
Dim Db As Database
Dim Td As TableDef

    Set Db = OpenDatabase("YourDataPath&Name")
    Set Td = Db.TableDefs("YourTableName")
    Td.Attributes = Td.Attributes Or dbHiddenObject Or dbSystemObject
    Db.Close

¦^¯Á¤Þ


¼W¥[ Columns Äæ¦ì(DataUnBound ª¬ªp)


¹D»ª©¤µMªº¤w±B¨k ¼¶¼g©ó¤å³¹ ...

§Ú¿ï¥Î¤FDBgrid«á¡A¥L¥uÅã¥Ü¨â¦æ(column)¸ê®Æ¡A¦ý¬O§Úªº¸ê®Æ®w¨ä¹ê¦³¥|­Ó¤£¦PÄæ¦ì¡A§ä¹M¤FDBgridªº¦UºØÄݩʳ£¨S¿ìªk§ï¡A§ä¨ì¹³DBgrid.Columns.countµ¥´XºØ¦³Ãöªº¸ê®Æ¡A¦ý³£ÄÝ©ó°ßŪ¡A½Ð°Ý¦³¤Hª¾¹D¦p¦ó¼W¥[DBgridªºÅã¥ÜÄæ¦ì¶Ü¡H

¦Ñ©Çµª¡G

¥Î Columns ¶°¦Xª«¥óªº Add ¤èªk¥h¼W¥[¡E½d¨Ò¦p¤U¡G
Private Sub Form_Load()
    DBGrid1.Columns.Add DBGrid1.Columns.Count
    DBGrid1.Columns(DBGrid1.Columns.Count - 1).Visible = True
End Sub
¨ä¥L½Ð°Ñ¦Ò Dbgrid.Columns.Add Help¡C

¦^¯Á¤Þ


¥Î TreeView ®i²{¸ê®Æ®w¤§¶¥¼hµ²ºc


¥Î¤ßªº¨k¤H..28·³ ¼¶¼g©ó¤å³¹

¶â....°²¦p§Úªºdatabase¬O¥H¤U
id       unit       up_id
101      A          101
102      B          101
103      C          101
104      D          101
105      AA         102
106      AB         103
107      AC         102
108      AD         104
109      AE         102
110      BB         105
111      BC         106
112      BD         107
113      BE         108
114      BF         109
115      BG         107
116      BH         105
117      BI         108
¥H¤W¤§¸ê®Æ¦p¦ó§Q¥ÎTREEVIEW²£¥Í¾ðª¬µ²ºc¡H

¦Ñ©Çµª¡G

'´ú¸Õ¥»½d¨Ò½Ð©óªí³æ¥¬¸m TreeView ±±¨î¶µ¡A¨Ã¤Þ¥Î Dao ª«¥ó¡C
Option Explicit

Dim Db As Database

Private Sub Command1_Click()
Dim nodX As Node
Dim Rela As Long
Dim RsA As Recordset
Dim RsB As Recordset

    Set RsA = Db.OpenRecordset("TabelName", dbOpenDynaset)
    Set RsB = RsA.Clone
    RsA.MoveFirst

    '­«ÂI¤@¡G¦]¬°ÀY¤@µ§¬O®Ú Node¡A¬G relative °Ñ¼Æ¤£¿é¡A®³¨ì
    '°j°é¥~°µ¥t¥~³B²z¡C
    '­«ÂI¤G¡GKey °Ñ¼Æ¤£¥u¤£±µ¨ü¼Æ­È¡A³s IsNumeric ªº¦r¦ê¤]¤£±µ¨ü¡A
    '©Ò¥H¥u¦n¦b«á­±¥[­Ó "A" ¦r¤¸¡A¸ò³o­Ó¹û§áªº TreeView §´¨ó¤@¤U¡C
    Set nodX = TreeView1.Nodes.Add(, , RsA!ID & "A", RsA!Unit)
    RsA.MoveNext

    Do While Not RsA.EOF
        RsB.MoveFirst
        RsB.FindFirst "ID = '" & RsA!ID & "'"

        '¦b¾ã­ÓTable ID Äæ¦ìùاä§ä¬Ý¦³µL¥»µ§°O¿ý UpID ­È¡A¨Ó¨M©w¥»°O¿ý¬O
        'Åܦ¨¤U¤@µ§©Î¥L°O¿ýªº¤l¶µ¥Ø¡C
        If RsB.NoMatch Then
            Rela = tvwNext
        Else
            Rela = tvwChild
        End If

        Set nodX = TreeView1.Nodes.Add(RsA!UpID & "A", Rela, RsA!ID & "A",RsA!Unit)
        RsA.MoveNext
    Loop
End Sub

Private Sub Form_Load()
    Set Db = OpenDatabase("DataPath&Name")
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Db.Close
End Sub

¦^¯Á¤Þ


°ÊºA¼W´îÄæ¦ì¬d¸ß


cheng ¼¶¼g©ó¤å³¹

°²³]¦b¤@ºô­¶¤¤¥Î 5 ­Ó checkbox ±ø¥ó¡A¤]´N¬O¸ê®Æ®wªºÄæ¦ì A,B,C,D,E µ¹ user ¿ï¾Ü¡A¦p¿ïÄæ¦ì A,C,E ®É¬° Select A,C,E From DB¡A¤S­Y¿ïÄæ¦ì A,E ®É¬° Select A,E From DB¡A¸Ó¦p¦ó°µ¡H

¦Ñ©Çµª¡G

Private Sub Command1_Click()
Dim SQLString As String
Dim AddField As String
Dim I As Integer
    SQLString = "SELECT "

    For I = 0 To Check1.Count - 1
        If Check1(I).Value Then
            AddField = AddField & "Field" & CStr(I + 1) & ","
        End If
    Next

    If Len(AddField) = 0 Then
        MsgBox "¨S¦³¿ï¾Ü¥ô¦ó¬d¸ßÄæ¦ì"
        Exit Sub
    Else
        AddField = Left(AddField, Len(AddField) - 1)
    End If

    SQLString = SQLString & AddField & " "
    SQLString = SQLString & "FROM YourTableName;"

    Debug.Print SQLString
End Sub

¦^¯Á¤Þ


Index ª«¥óªº¨Ï¥Î¤Î­­¨î


VBªì¾ÇªÌ

¦b EXCEL Ápµ²ªí¤¤¡A¬°¦ó DATA1.Recoderset.index="©m¦W" ¤@¥y³q¤£¹L?¡A??»Ý­n¦p¦ó³]¸m¡H

¦Ñ©Çµª¡G

Data.Recordset.Index ­n¦³§@¥Î¡A­n¦³¤U¦C¤T±ø¥ó¡G

  1. ¥u¯à¨Ï¥Î¦b MDB «¬ºAªº¸ê®Æ®w¤¤¡C
  2. ­n§A¨º Table ½T¹ê¦³³]¨º¼Ëªº Index Name¡A§A¥i¥Î¤U¦Cµ{¦¡¬d¥X¸Ó Table ¦³¨º¨Ç¥i¥Îªº Index¡G
    Option Explicit
    Dim TD As TableDef

    Private Sub Command1_Click()
    Dim ID As Index
        Set TD = Data1.Database.TableDefs("TableName")

        For Each ID In TD.Indexes
            Debug.Print ID.Name
        Next
    End Sub
  3. ¥²¶· Data1.RecordsetType=dbOpenTable(0)¡A¨ä¥L Dynaset ©M Snapshot «¬ºAªºRecordset ³£¤£¾A¥Î¡C
  4. ©Ò¥H Dao ªº Index ª«¥ó¬O¬° MDB ¸ê®Æ®w¶q¨­¥´³yªº¡A¹ï¨ä¥L§ÎºA¸ê®Æ®w¤ñ¸û¤£¾A¥Î¡A¦pªG­n¯à¦s¨ú¦hºØ¸ê®Æ®w¡AÁÙ¬OÀ³¸Ó¨Ï¥Î SQL ¬d¸ß±Ô­z¤¤ªº ORDER BY FieldName ©R¥O¤ñ¸û¦X¾A¡C

¦^¯Á¤Þ


°»´ú¨Ï¥ÎªÌ Click ªºÄæ¦ì


­n´²¤ß,Oh..Ya... ¼¶¼g©ó¤å³¹

¦pªG§Ú¦³¤@­ÓDBGrid,§Ú¥i¥Hª¾¹D¨Ï¥ÎªÌClick®É¬O«ö¨º¤@­ÓÄæ¦ì¶Ü???

¦Ñ©Çµª¡G

Private Sub DBGrid1_Click()
    Debug.Print DBGrid1.Columns(DBGrid1.Col).DataField
End Sub

¦^¯Á¤Þ


¨ú±oÄæ¦ìªø«×¨ÃÁקK¿é¤J¶W¹Lªø«×¸ê®Æ


²ïË稺°Õ~·s¦Ë ¼¶¼g©ó¤å³¹

½Ð°Ý¤@¤U¦b SQL Server ªºÀô¹Ò¤U¬O§_¦³´£¨Ñ¨ç¼Æ¥i¥Hª¾¹D¬Y­ÓÄæ¦ì ªºªø«×­­¨î¶Ü¡H

¦Ñ©Çµª¡G

Debug.Print Recordset.Fields(Index).Size

²ïË稺°Õ~·s¦Ë

¤S¦pªG­n¦bµ{¦¡¤¤Àˬd¨Ï¥ÎªÌ¿é¤JªºÄæ¦ì¬O§_¶W¹Lªø«×¡A¦³¨S¦³¤°»ò ¦n¿ìªk©O¡H

¦Ñ©Çµª¡G

'Field.Size ¬O¥H Byte ¬°³æ¦ì­pºâ¡A¤@­Ó¤¤¤å¨â Byte¡C
If LenB(StrConv("a¥[b¥[c", vbFromUnicode)) > Recordset.Fields(Index).Size Then
    Exit Sub
Else
    Recordset.Update
End If

¦^¯Á¤Þ


§ó§ï MDB ¸ê®Æ®w±K½X


¤ÑÃÈÃa¦Ñ¤½ ¼¶¼g©ó¤å³¹

¦p¦ó§ó§ï­ì¨Ó¦b MDB ¸ê®Æ®w³]©wªº±K½X¡H

¦Ñ©Çµª¡G

Option Explicit
Private Sub Command1_Click()
Dim Db As Database

    '¸ê®Æ®wÀÉ®×­n¥H¿W¦û¼Ò¦¡¶}±Ò¡A¥ç§Y²Ä¤G­Ó°Ñ¼Æ­n¬° True ¡C
    Set Db = OpenDatabase("c:\test\db1.mdb", True, False, ";pwd=NewPassword")
    Db.NewPassword "OldPassword", "NewPassword"

    Db.Close
End Sub

¦^¯Á¤Þ


¦^­º­¶

1