Dao »P SQL »yªk½d¨Ò(¤@)

¦^­º­¶


¤ÀÃþ

¼ÐÃD

¤j·N

§@ªÌ

¤é´Á

SQL »yªk ¨âÄæ¸ê®Æ¦X¦¨¤@Äæ Alias As ±Ô­zªº¥\¯à ¦Ñ©Ç 1998/8/1
SQL »yªk ¦hÄæÃöÁp¤Î¯Á¤Þ Alias As ±Ô­zªº¥\¯à ¦Ñ©Ç 1998/7/18
SQL »yªk ¦bSQL¤¤¨Ï¥Î¦Û­q¨ç¼Æªº°ÝÃD ¡@ ¦Ñ©Ç 1998/7/18
SQL »yªk Á`­p¬d¸ßªº SQL »yªk GROUP & HAVING ¦Ñ©Ç 1998/9/3
DAO ¾Þ§@ §PÂ_¬Y¤@­ÓTABLE¬O§_¦s¦b TableDefs ª«¥óªº¨Ï¥Î Rose 1998/7/3
DAO ¾Þ§@ ¶i¤J¥[±K¸ê®Æ®w WorkSpace.OpenDatabase() ¦Ñ©Ç 1998/8/2
DAO ¾Þ§@ ³¡¥÷¦r¦ê·j´M FindFirst & Like ¦Ñ©Ç 1998/8/7
DAO ¾Þ§@ ¨ú¥X¤Î¦^¶ñÄæ¦ì­È Field.Value ªº¨Ï¥Î ¦Ñ©Ç 1998/8/7
DAO ¾Þ§@ §PÂ_¬O§_§ä¨ì²Å¦Xªº°O¿ý EOF & BOF & AbsolutePosition ¦Ñ©Ç 1998/8/10
DAO ¾Þ§@ ¦b¬J¦sªº¸ê®Æªí·s¼WÄæ¦ì TableDef & Field ª«¥ó¨Ï¥Î ¦Ñ©Ç 1998/8/18
DAO ¾Þ§@ Dao ªº¾ã§å¥æ©ö°Ê§@(Transaction) WorkSpace ª«¥óªº¨Ï¥Î ¦Ñ©Ç 1998/8/18
DAO ¾Þ§@ ¦V MDB ¸ê®Æ®w¥[¤G¶i¦ì¸ê®Æ ¥Î AppendChunk ÆZ·F ¦Ñ©Ç 1998/8/21
DAO ¾Þ§@ ¤å¦rÀɸê®Æ®wªº¶}±Ò¤è¦¡ ­Ý½× Text ªº ISAM ¦Ñ©Ç 1998/8/30
DAO ¾Þ§@ DBGrid¤¤¦p¦ó±oª¾¥Ø«e©Ò¦bªº°O¿ý¦ì¸m AbsolutePosition ÄÝ©Ê ¦Ñ©Ç 1998/9/1
DAO ¾Þ§@ ±N MDB Table ¿é¥X¦¨¤å¦rÀÉ Dao »P File I/O ¦X§@ ¦Ñ©Ç 1998/9/1
DAO ¾Þ§@ bookmark ¦p¦ó°µÅÞ¿è§PÂ_ ByteArray ªºÂà´« JeffLin 1998/9/2
DAO ¾Þ§@ ¦Û»s¦Û°Ê½s¸¹Äæ¦ì ¡@ ¦Ñ©Ç 1998/9/3
DAO ¾Þ§@ ¦ü¬O¦Ó«Dªº RecNo AbsolutePosition ¦Ñ©Ç 1998/9/5
DAO ¾Þ§@ ¦b VB ùØÀ£ÁY MDB ¸ê®Æ®w CompactDatabase ¦Ñ©Ç 1998/9/5
DAO ¾Þ§@ ¥Î VB ¶} Excel Sheet ªí ¡@ ¦Ñ©Ç 1998/9/9
¸ê®ÆÆ[©À ¦p¦ó³W¹º Foreign Key ¸ê®ÆªíªºÃöÁp ¦Ñ©Ç 1998/8/5
¸ê®ÆÆ[©À ¤@¹ï¦h»P¥ª¥k³s±µ ¸ê®Æªíªº³s±µ ¦Ñ©Ç 1998/9/11
¸ê®ÆÆ[©À ¦hªí¬d¸ßªº³´¨À ¥|³B®I¥ñªº Null ­È ¦Ñ©Ç 1998/9/11

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. ¥»½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
  3. ¦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
  4. ¥»½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

¦^¯Á¤Þ


¨âÄæ¸ê®Æ¦X¦¨¤@Äæ


Bee ¼¶¼g©ó¤å³¹

§Úªº¸ê®Æ®w¤¤¦³¤@Äæ¬OÁ`»ù,µ¥©ó³æ»ùÄæ*¼Æ¶qÄæ, ½Ð°Ý¨º¤@¬qÅýÁ`»ù¦Û°Êºâ¥Xªºµ{¦¡½X­n©ñ¦b¨º¸Ì(©Î¨º­Ó¨Æ¥ó¤¤)>   ¤~¥i¥HÅýUSER¦b¿é¤J§¹³æ»ù©M¼Æ¶q«á´N±o¨ìÁ`»ù?

¦Ñ©Çµª¡G

¨ä¹ê¦X­pÄæ¦ì¥Î SQL »yªk¨ú¥N¡A·|§ó¬ÙºÏºÐªÅ¶¡¡A¤]§ó¤è«K¾Þ§@¡A§A°Ñ¬Ý¤U¦C¦¡¤l¬Ý¬Ý¡C

SELECT Good.GoodID, Good.GoodName, Good.Unit, Good.Price, [Unit]*[Price] AS ¦X­p FROM Good;

»¡©ú¡G

  1. [¹Bºâ¦¡] As [Äæ¦ì¦WºÙ] ¡A´N·|§â¹Bºâ«áªº­ÈÂ\¦bµ¹©w¦WºÙªº¨º­Ó·sÄæ¦ìùØ¡A¦n¹³§A·s¼W­ÓÄæ¦ì¤@¯ë¡C
  2. [Äæ¦ì¦WºÙ] As [¥t¤@¦WºÙ] ¡A§@¥Îµ¥©ó Field.Name ¹ï Field.Caption ªºÃö«Y¡A¤]´N¬O Name ¬O©T©wªº¡A¦ý Caption ¥i¥H¨Ì»Ý­nÀH®É§ï¡C

¦^¯Á¤Þ


¶i¤J¥[±K¸ê®Æ®w


Option Explicit

Dim Ws As Workspace
Dim Db As Database
Dim Rs As Recordset

Private Sub Form_Load()
Set Ws = DBEngine.Workspaces(0)
Set Db = Ws.OpenDatabase("DBName", False, False, ";pwd=SecretString")
Set Rs = Db.OpenRecordset("RecordsetName")
Set Data1.Recordset = Rs
End Sub

¦^¯Á¤Þ


¦p¦ó³W¹º Foreign Key


±H¥óªÌ: ¥[µá

¥D¦®: [Database] ¦ó¿× Foreign Key ?

¦Ñ©Çµª¡G

¦^¯Á¤Þ


³¡¥÷¦r¦ê·j´M


¹ï¿ù³£¬O¬°¤F·R ¼¶¼g©ó¤å³¹

°²¦p»¡¬Y¤@­ÓÄæ¦ìªº¤º®e¬O¡G

  1. ¥xÆW·L³n¤½¥q
  1. ­^¥Nº¸¤½¥q
  1. ¥xÆW IBM

­n¦p¦ó¦b·j´M®É¥u¥´¤J"·L³n"´N¥i¥H§â¨º¤@µ§¸ê®Æµ¹§ì¥X¨Ó¡H

¦Ñ©Çµª¡G

YourRecordset.FindFirst "FieldName Like '*·L³n*'"

¦^¯Á¤Þ


¨ú¥X¤Î¦^¶ñÄæ¦ì­È


Boring Summer ¼¶¼g©ó¤å³¹

½Ð°Ý¦p¦ó¦bVB³s¨ì¸ê®Æ®w«á¡A±N¸ê®Æ®w¤¤ªº¸ê®ÆÂ^¨ú¥X¨Ó¹Bºâ¡A¤]´N¬O§â¸ê®ÆŪ¨ìÅܼƤ¤¡AµM«á¹ïÅܼƧ@¹Bºâ¡I¡I

¦Ñ©Çµª¡G

  1. §ì¥X¸ê®ÆÄæ¦ì­È¡G
    YourVariable=YourRecordset!FieldName
  2. ¦^¦s¸ê®ÆÄæ¦ì­È¡G
    YourRecordset.Edit(³o¬O½s¿è¼Ò¦¡¡A·s¼W¼Ò¦¡«h¬O YourRecordset.Addnew)
    YourRecordset!FieldName=YourVariable
    YourRecordset.Update
  3. ½Ðª`·NÅܼƫ¬ºA¥²¶·»PÄæ¦ì«¬ºA¬Û¦P¡A§_«h·|¦³¿ù»~µo¥Í¡C
  4. ­n¦Ò¼{ÅܼƼe«×»PÄæ¦ì¼e«×°ÝÃD¡C

¦^¯Á¤Þ


§PÂ_¬O§_§ä¨ì²Å¦Xªº°O¿ý


  1. §Ú­Ì¥H±ø¥ó SQL ±Ô­z¶}±Ò¸ê®Æ®w®É¡A±`·|¦³§ä¤£¨ì²Å¦X¸ê®Æ°O¿ýªº±¡ªpµo¥Í¡A³o®É¶Ç¦^ªº Recordset ¬OªÅªº¡C
  2. °w¹ï¤@­ÓµL°O¿ýªº Recordset ¡A¤£ºÞ¬O²¾°Ê°O¿ý©ÎÅã¥Ü°O¿ý¡A³£·|²£¥Í¨t²Î¿ù»~¡A ©Ò¥H¦b§Ú­Ì¸ê®Æ¿ý¤@¶}±Ò«á¡AÀ³¥ß§Y°µªÅ¸ê®Æ¿ýÀˬd¡A¥H½T«Oµ{¦¡µL»~¡C
  3. §PÂ_ªÅ¸ê®Æ¿ýªº½d¨Ò¡G

    '¦³¸ê®Æ¿ý¬O 0¡A¨S¸ê®Æ¿ý¬O -1
    If Recordset.AbsolutePosition = -1 Then
        '¤£­nÅã¥Ü¸ê®Æ¤Î¨ä¥L°Ê§@
    Else
        'Åã¥Ü¸ê®Æ¤Î¨ä¥L°Ê§@
    End If

    '¨S¸ê®Æ¿ý®É Bof ©M Eof ³£·|¬O True
    If Recordset.BOF And Recordset.EOF Then
        '¤£­nÅã¥Ü¸ê®Æ¤Î¨ä¥L°Ê§@
    Else
        'Åã¥Ü¸ê®Æ¤Î¨ä¥L°Ê§@
    End If

¦^¯Á¤Þ


§PÂ_¬Y¤@­ÓTABLE¬O§_¦s¦b


Public Function CheckTableExist(tData As Database, TableName As String) As Boolean
Dim I As Integer
CheckTableExist = True
    For I = 0 To tData.TableDefs.Count - 1
        If UCase(tData.TableDefs(I).Name) = UCase(TableName) Then
            CheckTableExist = False
            Exit Function
        End If
    Next I
End Function

¦^¯Á¤Þ


¦hÄæÃöÁp¤Î¯Á¤Þ


½÷¥J on July 13, 1998

½Ð°Ý«ç¼Ëmake Relation between two field but not one field

¦Ñ©Çµª¡G

¥Î¤T­Ó QueryDef ¨Ó¹F¦¨
1.Addfield1:
SELECT [Fdate]+[Ftime] AS JoinKey, RD01.Fdate, RD01.Ftime, RD01.Level
FROM RD01
ORDER BY [Fdate]+[Ftime];

2.Addfield2:
SELECT [Fdate]+[Ftime] AS JoinKey, MRD01.Fdate, MRD01.Ftime, MRD01.MLevel
FROM MRD01
ORDER BY [Fdate]+[Ftime];

3.AddAllField:
SELECT AddField1.Fdate,
AddField1.Ftime, AddField1.Level, AddField2.Fdate,
AddField2.Ftime, AddField2.MLevel
FROM AddField1 INNER JOIN AddField2 ON
AddField1.JoinKey = AddField2.JoinKey;

¦^¯Á¤Þ


¦b¬J¦sªº¸ê®Æªí·s¼WÄæ¦ì


Smith ¼¶¼g©ó¤å³¹

½Ð°Ý¦p¦ó¦b¤@­Ó¤w¦s¦bªºtable¤¤¦A¥[¤W¤@­Ófield(Äæ¦ì)©O

¦Ñ©Çµª¡G

Option Explicit
Dim Db As Database
Dim Tb As TableDef
Dim Fd As Field
Private Sub Form_Load()
    Set Db = OpenDatabase("c:\user\mytest.mdb")
    Set Tb = Db.TableDefs!Good
    Set Fd = Tb.CreateField("YouPut", dbText)
    Fd.Size = 20
    '¥[¤JÄd¦ì
    Tb.Fields.Append Fd

    '§R°£Äæ¦ì
    Tb.Fields.Delete "YouPut"
End Sub
Private Sub Form_Unload(Cancel As Integer)
    Db.Close
End Sub

¦^¯Á¤Þ


Dao ªº¾ã§å¥æ©ö°Ê§@(Transaction)


linus ¼¶¼g©ó¤å³¹

®Ñ¤W»¡Jet Engine¤ä´©Transaction Management,§Ú¥Îvb5+access 7.0 «o¸Õ¤£¥X¨Ó,(¨S¦³error,¦ý¬O³£¨S¦³µo¥Íupdate¤Îdelete)

¦Ñ©Çµª¡G

Option Explicit
Dim DJet As New DBEngine
Dim Wk As Workspace
Dim Db As Database
Dim Rs As Recordset

'§¹¦¨¾ã§å¥æ©ö
Private Sub Command1_Click()
    '¦pªG Rs ª«¥ó¤£¤ä´©¾ã§å¥æ©ö«hµ²§ô Sub
If Not Rs.Transactions Then Exit Sub

Rs.MoveFirst
    Wk.BeginTrans

    Do While Not Rs.EOF
        Rs.Edit
        Rs.Fields(2).Value = "123"
        Rs.Update
        Rs.MoveNext
    Loop

    Wk.CommitTrans
End Sub

'´_­ì¾ã§å¥æ©ö
Private Sub Command2_Click()
    '¦pªG Rs ª«¥ó¤£¤ä´©¾ã§å¥æ©ö«hµ²§ô Sub
If Not Rs.Transactions Then Exit Sub

    Rs.MoveFirst

    Wk.BeginTrans

    Do While Not Rs.EOF
        Rs.Edit
        Rs.Fields(2).Value = "456"
        Rs.Update
        Rs.MoveNext
    Loop

    Wk.Rollback
End Sub

Private Sub Form_Load()
    Command1.Caption = "Commit"
    Command2.Caption = "Rollback"

    Set Wk = DJet.Workspaces(0)
    Set Db = Wk.OpenDatabase("c:\user\mytest.mdb")
    Set Rs = Db.OpenRecordset("Good")

    '¨S¦³°O¿ý«hµ²§ô
    If Rs.EOF And Rs.BOF Then
        Unload Me
    End If
End Sub

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

­nª`·Nªº¬O¦b BeginTrans ¤§«e¡ARs ­n¥ý MoveFirst ¡A§_«h§Aªº record ¦pªG¦b Eof ¡A·íµM¨S°µ´Nµ²§ô¤F¡C

¦^¯Á¤Þ


¦bSQL¤¤¨Ï¥Î¦Û­q¨ç¼Æªº°ÝÃD


­â¶³ÃM ¼¶¼g©ó¤å³¹

¦³¤@­Ó¦Û­q¨ç¼Æ backsum()
      public function backsum()
      .......
      end function
      °²¦p°õ¦æ:
      sql1="select backsum as BCCT from tablemname"
µ²ªG²£¥Í backsum ¨ç¼Æ¥¼©w¸qªº¿ù»~¡A¦p¦ó¤~¯à¥¿½T¡H

¦Ñ©Çµª¡G

sql1="select " & backsum() " as BCCT from tablemname"

¦^¯Á¤Þ


¦V MDB ¸ê®Æ®w¥[¤G¶i¦ì¸ê®Æ


powerboy

¦p¦ó¥Î VB ¦V Access ²K¥[¤G¶i¨î¤å¥ó¡A¦p²K¥[¤@ Zip ¤å¥ó¨ì Access ?

¦Ñ©Çµª¡G

  1. ­º¥ý§A­n¥[¤G¶i¨î¸ê®ÆªºÄæ¦ì¥²¶·¬O Memo or LongBinary.
  2. ¶}±Ò¸ê®Æ®w
    Dim Db As Database
    Dim Rs As Recordset
        Set Db = OpenDatabase("YourDataBasePathAndName")
        Set Rs = Db.OpenRecordset("YourTabelName")
  3. Ū¨ú¤G¶i¨îÀÉ®×
    Dim Buff() As Byte
    Dim FileHandle As Integer
        FileHandle = FreeFile
        Open "YourZipPathAndName" For Binary As #FileHandle
        ReDim Buff(LOF(FileHandle) - 1)
        Get #FileHandle, , Buff
        Close #FileHandle
  4. ¥Î AppendChunk §â Buff ¥[¨ì LongBinary Äæ¦ìùØ
        Rs.AddNew
        Rs!FieldName.AppendChunk Buff
        Rs.Update
  5. ¥Î GetChunk ¨ú¥X LongBinary Äæ¦ìùتº¸ê®Æ
    Dim Buff() As Byte
        ReDim Buff(Rs!Image.FieldSize - 1)
        Buff = Rs!FieldName.GetChunk(0, Rs!Image.FieldSize)
  6. §â¨ú¥X¤§ Buff ¸ê®Æ¦^¦sµwºÐÀɮפ¤
    Dim FileHandle As Integer
        FileHandle = FreeFile
        Open "OutPutZipName" For Binary As #FileHandle
        Put #FileHandle, , Buff 
        Close #FileHandle
  7. ÁöµM¥H¤W¤èªk¥i¥H¹F¦¨¥[¤J¤G¶i¦ì¸ê®Æ(¨ä¹ê´N¬O¥ô¦ó¹q¸£¸ê®Æªº·N«ä¡A¥]¬A°õ¦æµ{¦¡¡C)ªº¥Øªº¡A¦ý¬O¦Ñ©Ç¤£¹ªÀy¤j®a³o»ò°µ¡A¦]¬°¹L¤jªºÄæ¦ì¦³¤U¦C¯ÊÂI¡G

¦^¯Á¤Þ


¤å¦rÀɸê®Æ®wªº¶}±Ò¤è¦¡


¦Ì©_ ¼¶¼g©ó¤å³¹

§Ú¥ÎData»PDBGrid¨â±±¨î¶µ±ýª½±µ¶}±Ò¤@¤å¦rÀɽT¥X²{³o¼Ëªº°T®§...."§ä¤£¨ì¥i¦w¸ËªºISAM "§Ú¬Ý¤F¬Ý»¡©úÀɬÛÃöªº¤º®e....·N«ä¦n¹³¬O­n¥hregedit¤¤°µ­×§ï...¡H¡H ¬O¶Ü¡H  ¨º­n«ç»ò°µ©O¡H¡H

¦Ñ©Çµª¡G

  1. ¦pªG§Aªº¤å¦rÀɬOÄÝ©ó¤U¦C³oºØ¡G

    "No","Name","Level","Class"
    "0001","¾G¬K¦n","1","¥Ò"
    "0002","¿àºÑ®ç","1","¤A"
    "0003","³¢¬K¾ð","2","¥Ò"
    "0004","ªL¦w­}","2","¥Ò"
    "0005","³¯«iªQ","2","¤A"

    ¦³©T©w®æ¦¡ªº¤å¦rÀÉ(¤SºÙ CSV ÀÉ)

    §A¥i¥H¥Î

    Dim Db As Database
    Dim Rs As Recordset
    Private Sub Form_Load()
        Set Db = OpenDatabase("¥Ø¿ý¸ô®|", False, False, "TEXT;")
        Set Rs = Db.OpenRecordset("¤å¦rÀɦW")

        Set Data1.Recordset = Rs
    End Sub

    ±Ô­z§â¤å¦rÀÉ©ñ¶i DBGrid ùØ¡C
  2. ­Y¬O®æ¦¡¤ñ¸û¥j©Ç¡A´N­n°µ¤@­Ó Schema.ini ©ñ¦b¤å¦rÀɪº¦P¥Ø¿ý¤U°µ¬° ISAM¡C¦Ü©ó Schema.ini ­n¦p¦ó°µ½Ð°Ñ¦Ò VB Online Help ¸ê®Æª«¥ó¦s¨ú¤â¥U,¦s¨ú¥~³¡¸ê®Æ,¨Ï¥Î¤å¦rÀɳo¤@¸`¡C
  3. ¤£¹L«Ü°Q¹½ªº¤@ÂI´N¬O³o¼Ë¨ú±oªº¤å¦r¸ê®Æ¥u¯à·s¼W¡AµLªk§ó·s¡C¦Ü©ó¥Î³]©w Data1.DatabaseName ©M RecordSource ¨Ó¨ú TextFile ¡A¦n¹³¤£ºÞ¦³¨S¦³Schema.ini ¡A³£·|¥¢±Ñ¡AÁÙ¬O¥H«e­± »¡©ú 1. ªº¤è¦¡¶}±Ò¬°©y¡C

¦^¯Á¤Þ


DBGrid¤¤¦p¦ó±oª¾¥Ø«e©Ò¦bªº°O¿ý¦ì¸m


¨«¹L¥|¤è¦^¨ì­ìÂI ¼¶¼g©ó¤å³¹

·í§Ú²¾°ÊTable¤¤½bÀY«ü¦V¨ä¤¤¤@­Ó°O¿ý®É­n¦p¦ó±oª¾¥Ø«e¦¹°O¿ý¬O²Ä´Xµ§°O¿ý©O¡H¤S·í§Ú§Q¥Î·j´Mªº¤èªk¥h§ä²Å¦X¬YºØ±ø¥óªº°O¿ý®É­n«ç¼Ë¤~¯à±N«ü¼Ð«ü¦V¦¹¤@°O¿ý¨ÃÅã¥Ü¦b¥HDBGrid§@¥X¤§table¤W©O¡H¡H

¦Ñ©Çµª¡G

  1. Option Explicit
    '½Ð¦b Form ¤W¥¬¸m Command1,Data1,DBGrid1,
    '¨ÃÅý DBGrid.DataSource=Data1
    Dim Db As Database
    Dim Rs As Recordset
    Private Sub Command1_Click()
        '¦]¬°¦b Form_Load ùاڭ̥ΠSet Data1.Recordset=Rs
        '¨Ï Data »P Rs ³s°Ê¡A©Ò¥H§A¥u­n°õ¦æ Find «ü¥O¡A
        'DBGrid «ü¼Ð¦Û¤v·|¸õ¹L¥h
        Rs.MoveFirst
        Rs.FindFirst "Serial=3"
    End Sub
    Private Sub Data1_Reposition()
        'ª`·N!!¥u¦³dbOpenDynaset or dbOpenSnapshot
        '¤~¥i¥H¨Ï¥Î Rs.AbsolutePosition ªºÄÝ©Ê
        'Recordset ªº²Ä¤@µ§°O¿ý¬O 0
        '³o­Ó±Ô­z¯àÅý DataControl Åã¥ÜÁ`°O¿ý¤Î¥Ø«e°O¿ý«ü¼Ð
        Data1.Caption = CStr(Rs.AbsolutePosition + 1) & "/" & Rs.RecordCount
    End Sub
    Private Sub Form_Load()
        Set Db = OpenDatabase("c:\user\mytest.mdb")
        Set Rs = Db.OpenRecordset("Student", dbOpenDynaset)
        '§â Rs °O¿ý«ü¼Ð²¾¨ì³Ì«á¤@¦¸¡A°µ¥X¨Óªº Rs.RecordCount ¤~·|¥¿½T
        Rs.MoveLast
        Rs.MoveFirst
        Set Data1.Recordset = Rs
    End Sub
  2. ½Ð¨Ì§A¦Û¤vªº¸ê®Æ®wª¬ªp­×§ï¤W¨Ò¡C

¦^¯Á¤Þ


±N MDB Table ¿é¥X¦¨¤å¦rÀÉ


¤p«e¾W ¼¶¼g©ó¤å³¹

­ì¥ý¶}±Ò¤§*.mdbÀɤ¤ªº¸ê®Æªí¦³¦ó¸û§Ö³tªº¤èªk±N¸ê®Æ*.mdbÂà´«¦¨¤å¦rÀÉ??¦]¬°¤W­zªº¤èªk¹ê¦b¬O¤ÓºC¤F....¦pªG¸ê®Æ¶q¤j¡]¤W¤dµ§¡^>µ¥«Ý®É¶¡¯u¬O¤Ó¤[¤F»¡.....

¦Ñ©Çµª¡G

  1. §A¬O«ç»ò¿é¥Xªº¡A¥Î§Ú¤U¦Cªº¦¡¤l§A¥h¿é¥X VB5 ¤U¦³­Ó Biblio.mdb ªº Authors ¸ê®Æªí¡A16000 µ§°O¿ý¡A°÷¦h¤F§a¡A¦b§Úªº AMD X6-2 ¾÷¾¹¤W®É¶¡ 1 ¦Ü 2 ¬í¡A´Nºâ486 ¡AÀ³¸Ó¤]¤£·|¶W¹L 10 ¬í¡A¦pªG DBGrid Åý§Aı±o¤ÓºC¡A¨º´N½Ðª½±µ¾Þ§@ Dao¡C
  2. Option Explicit
    Dim Db As Database
    Dim Rs As Recordset

    Private Sub Form_Click()
    Dim FileHandle As Integer
    Dim I As Integer
    Dim OutString As String
    Dim Calc As Double
        Calc = Now
        Me.MousePointer = 11
        Rs.MoveFirst

        FileHandle = FreeFile

        Open "c:\temp\out.txt" For Output As #FileHandle

        Do While Not Rs.EOF
            OutString = ""
            For I = 0 To Rs.Fields.Count - 1
                OutString = OutString & Rs.Fields(I).Value & ","
            Next
            OutString = Mid(OutString, 1, Len(OutString) - 1)
            Print #FileHandle, OutString
            Rs.MoveNext
        Loop

        Close #FileHandle
        Calc = Now - Calc
        Debug.Print "¬í¡G" & Second(Calc)
        Me.MousePointer = 0
    End Sub

    Private Sub Form_Load()
        Set Db = OpenDatabase("c:\temp\biblio.mdb")
    '                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ¦¹³B½Ð°t¦X§A¦Û¤vªº¸ô®|­×§ï
        Set Rs = Db.OpenRecordset("authors", dbOpenDynaset)
    End Sub

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

¦^¯Á¤Þ


bookmark ¦p¦ó°µÅÞ¿è§PÂ_


°í­ô ªº¤å³¹¤¤´£¨ì:

§Ú¥Î¤Fclassline_head  ©Mclassline_tail¨â­Ó¼Æ³]©w¦¨VariantµM«á°O¿ýdata1.recordset.bookmark ¦ý¬O·í§Ú¼g¨ì¤F while not data1.recordset.bookmark=classline_head     ........     loop®É¹q¸£¦b°õ¦æ«á´N¸ò§Ú»¡¸ê®Æ«¬ºA¤£²Å.......

Jeff Lin 榭G

Bookmarkªº°ò¥»«¬ºA. ­Y¥Hvariant±µ¦¬, ¤@©w·|¦¬¨ìbyte array. µM¦Óbyte array¬O¤£¯àª½±µ¤ñ¸ûªº (¥ô¦óarray³£¤@¼Ë).«Øij±z©w¸q¬°string, ±µ¦¬¤§«á´N¥i¥H¤ñ¸û¤F.

¦Ñ©Ç´¡ªá¡G

  1. ­n¥Î BookMark °µÅÞ¿è§PÂ_¡A­n°Ê¥Î¨â­Ó¦r¦êÅܼơA
  2. dim classline_head as String
    classline_head=data1.recordset.bookmark
    °O¿ý²Ä¤@­Ó BookMark
  3. dim classline_tail as String
    classline_tail=data1.recordset.bookmark
    °O¿ý²Ä¤G­Ó BookMarkloop
  4. µM«á¤~¯à
    if classline_head=classline_tail then ..............
  5. ©Ò¥H BookMark ¥Î¨Ó°µ³æ¯Âªº²¾¦ì¤u¨ã¤ñ¸û¦n¡A¥Î°µ¤ñ¸û¹Bºâ¡AÀ³§Q¥Î¸ê®Æ¿ýùتºPrimaryKey Äæ¦ì­È¤ñ¸û¾A·í¡A¥Î BookMark °µ¤ñ¸û¯uªº¬JÅo¶Û¤S³Â·Ð¡C

¦^¯Á¤Þ


¤@¹ï¦h»P¥ª¥k³s±µ


ÃöÁp»P³s±µªºÃö«Y

¦b¦¹¦Ñ©Ç­n¸ò¤j®a½Íªº¬O¸ê®Æ®w¤¤¡AÃöÁp»P³s±µªºÃö«Y¡AÃöÁp»P³s±µ¨ì©³¦³¦óÃö«Y©O¡H¨ä¹ê¬O¤@¥ó¨Æ¡C´N¬O·í§Ú­Ì¥Î Dao CreatRelation ¤èªk«Ø¥ß¤@­Ó Relation ª«¥ó¡A©Î SQL ±Ô­z¤¤¥Î Join ±Ô­z³s±µ¨â­Ó Table ®É¡A´N²£¥Í¤F³o­ÓÃöÁp¤SºÙ³s±µª¬ºA¡A¥u¤£¹L¬°¤F°Ï§O¤è«K¡A§Ú­Ì¦h§â Relation ªº³]©w¥sÃöÁp¡A¦Ó§â SQL JOIN ±Ô­z¥s³s±µ¡C

¤@¹ï¦h»P¥ª¥k³s±µ

¬JµMÃöÁp»P³s±µ¬O¤@¥ó¨Æ¡A¨º¦b Access 97 ½s¿èÃöÁpùسs±µÃþ«¬³]©w¤S¬O¤°»ò·N«ä¡A¤]´N¬O¤@¹ï¤@ÃöÁp©M¤@¹ï¦hÃöÁp¬O¥Ñ Join «¬ºA¨M©wªº¶Ü¡HInner Join ¬O¤@¹ï¤@¡HLeft Join ©M Right Join ¤~¬O¤@¹ï¦h¡H¨ä¹ê§¹¥þ¿ù¤F¡AÄÝ©óÃöÁpÃþ«¬ªº¤@¹ï¤@©M¤@¹ï¦h¡A©MÄÝ©ó³s±µÃþ«¬ªº¥ª¥k³s±µ§¹¥þ¬O¨â¥ó¤£¦PÄݩʪºªí²{¡A¦UºÞ¦Uªº¡A½Ö¤]¤£¤z¯A½Ö¡C

¤@¹ï¦h»P¤@¹ï¤@ªºÃöÁpÃþ«¬¦p¦ó³]©w

µª®×¬O¨Sªk³]©w¡A¦]¬°¬ÛÃöÁpªº¨â±i¸ê®Æªí¡A¥DÃöÁp¸ê®ÆªíªºÃöÁpÄæ¦ì¥²¶·¬O±©¤@Áä­Èªº¯Á¤ÞÄæ¡A¦pªG³QÃöÁp¸ê®ÆªíªºÃöÁpÄæ¦ì¤]¬O±©¤@Áä­Èªº¯Á¤ÞÄæ¡A¨º³oÃöÁp´N¬O¤@¹ï¤@¡A¦Ó¦pªG³QÃöÁpÄæ¦ì¨Ã«D±©¤@Áä­È¡A¨º¨âªÌÃöÁp´N¬O¤@¹ï¦h¡C¤]´N¬O»¡ÃöÁpÃþ«¬¨M©w©ó¿ï¥Î¨º¨â­ÓÄæ¦ì°µÃöÁp¤§®É¡C

¥ª¥k³s±µªº§@¥Î

§Aªº JOIN ¤£ºÞ¬O INNER ¡BLEFT or RIGHT ¡A³£¤£·|¹ï¤@¹ï¤@©Î¤@¹ï¦hÃöÁpÃþ«¬²£¥Í¥ô¦ó¼vÅT¡A¥¦ªº§@¥Î¬O¥u¦³¦b¥DÃöÁp¸ê®Æªí¤Î³QÃöÁp¸ê®Æªí¤¤¡A¯Á¤Þ­È¤£¦¨¹ï¥X²{®É¤~¦³§@¥Î¡C¤]´N¬O»¡·í¥DÃöÁp¸ê®Æªí¤¤¦³¨ÇÃöÁpÁä­È¦b³QÃöÁp¸ê®Æªí¤¤§ä¤£¨ì¡A©Î¬O±¡ªp¤Ï¹L¨Ó¡A³o®É¨º¨Ç¯Ê¤@Ã䱡§ÎªºÄæ¦ì­È¬O§_­n§e²{¡A´N¥Ñ INNER ¡BLEFT or RIGHT ¨M©w¡C

½d¨Ò»¡©ú¡G

¥DÃöÁp¸ê®Æªí

MasterID Note
1 M_Rec_1
2 M_Rec_2
3 M_Rec_3

³QÃöÁp¸ê®Æªí

SuBID MasterNo Note
1 1 S_Rec_1
2 1 S_Rec_2
3 1 S_Rec_3
4 2 S_Rec_4
5 4 S_Rec_5
6 4 S_Rec_6

¨â¸ê®Æªí¥H MasterID ÃöÁp MasterNo ¡A¬°¤@¹ï¦hÃöÁp

³Ì«áªº¼G¥o¡G

³oÁöµM¬O MDB ¸ê®Æ®w«Ü°ò¥»ªº·§©À¡A¦ý¦pªG§AµLªk¥R¤À´x´¤¥¦·|¹ï§A¸ê®Æ¿ý²£¥Í¦óºØ¼vÅTªº¸Ü¡A§A´NµLªk½ñ¤JÃöÁp¸ê®Æ®wªº°ó¶ø¡A¦Ó¥u¯à³æ±i¸ê®Æªí¦b¨ºª±¨Óª±¥h¡A¦Ü©ó¸ê®Æ³W¹º¡B¸ê®Æ¤ÀªR§ó¬O¤£¥i¯àªº¤F¡C©Î³\§A¦­´Nª¾¹D³o¨Ç¤F¡A¨º§Ú®¥³ß§A¡A§Ú¥u¬O¬è¬ßµÛ¦³¨Ç¹³·í®É¦~»´ªº§Úªº Program ªì¾ÇªÌ ¡A¯à¦bŪ¤F³o½g¤å³¹«á¡AÁŵM¶}®Ô¡A¹Ä¹D­ì¨Ó³o»ò¦^¨Æ¡A¬O§Ú­Ì¦Û¤v·Qªº¤Ó½ÆÂø¤F¡C

¦^¯Á¤Þ


¦hªí¬d¸ßªº³´¨À


ÁÙ°O±o§Ú¦b [¤@¹ï¦h»P¥ª¥k³s±µ] ¨º½g½d¨Ò¤¤½Í¨ì¥ª¥k³s±µ®Éªº¸ê®Æ§e²{´¿³o¼Ë¥´¥X¸ê®Æ
M_Rec_1,S_Rec_3
M_Rec_2,S_Rec_4
Null,S_Rec_5
Null,S_Rec_6
Áo©ú¦p§A¬O§_¤wÁp·Q¨ì¡AÃø¹D¸óªí¬d¸ß·|²£¥Í Null ­È¡H¤@ÂI³£¨S¿ù¡A¦pªG§A¥Î INNER JOIN¡A¨º¸ê®Æ¿ý¬O¦¨Âù¥X²{ªº¡A°£«D§A­ì¨ÓÄæ¦ì¬O Null¡A§_«h¤£¥i¯à²£¥Í Null¡C¦ý¦pªG¥Îªº¬O LEFT JOIN ©Î RIGHT JOIN ¡A¨º¯Ê®uªº¤@Ãä´N¬O Null ­È¡A¨º©È§A­ì¨Ó©Ò¦³Äæ¦ì³£¤£¬O Null ¡A¤@¼Ë·|²£¥Í Null ­È¡A§óÁVªº¬O´Nºâ³o­ÓÄæ¦ì¬O¼Æ­È«¬ºA¡A¬d¸ß©Ò±oµ²ªG¤@¼Ë¬O Null¡C¦Ó¦pªG§A­n¹ï¥¦°µ¹Bºâ¡Aµ²ªG·íµM³£¬O Null¡A¤£ºÞ§A¦b¸ê®ÆªíÄæ¦ì³]­p®É«ç¼Ë¤p¤ß¡A³£µLªkÁקK¡C

¦^¯Á¤Þ


Á`­p¬d¸ßªº SQL »yªk


¤j¬ü¤ksally ¼¶¼g©ó¤å³¹

item = .dbf ªº¸ê®Æ®w ,¸ê®ÆÀx¦s¤è¦¡¬°
=>   orderno  catologNO  quantity ...
       =======  ========  ======
ex: A0001     aaa                1
      A0001     bbb                5
      A0001     ccc                4
§Æ±æ±o¨ìªºµ²ªG¬O
orderno = 'A0001' ªºÁ`¼Æ¶q

¦Ñ©Çµª¡G

SELECT orderno, Sum(quantity) AS Á`­p
FROM item
GROUP BY orderno
HAVING orderno="A0001";

¦^¯Á¤Þ


¦Û»s¦Û°Ê½s¸¹Äæ¦ì


¥¿¦b¥¢·~¤¤...(man) ¼¶¼g©ó¤å³¹

¦bdatabase·s¼W¤@µ§¸ê®Æ¦ý­q³æ§Ç¸¹©Î¬O¾P³f³æ§Ç¸¹¬O©T©w¦Û°Ê²£¥Íªº

¦Ñ©Çµª¡G

  1. ¦b MDB ¸ê®Æ®wùئ³¦Û°Ê¼W¸¹ªºÄæ¦ì«¬ºA¡A§A³]©w¥¦´N¥i¥H¦Û°Ê¼W¸¹¡C
  2. ¦pªG§A¨Ï¥Îªº¸ê®Æ®wµL¦Û°Ê¼W¸¹«¬ºAÄæ¦ì¡A©Î§A¤£·Q¿ï¥Î¦¹ºØÄæ¦ì¡A½Ð°Ñ¦Ò¤U­±ªºµ{¦¡¡G

    Option Explicit
    Dim Db As Database
    Dim Rs As Recordset
    '¦Û°Ê¼W¸¹ÅܼÆ
    Dim AddNo As Long
    Private Sub Command1_Click()
    Dim FLength As Integer

        '¨ú±o¦Û°Ê½s¸¹Äæ¦ìªø«×
        FLength = Rs!SerialID.Size
        '¦Û°Ê½s¸¹¥[¤@
        AddNo = AddNo + 1

        '·s¼W¤@µ§
        Rs.AddNew
        Rs!Note = Text1.Text
        'AddNo Âন¦r¦ê¡A«e­±¸É "0"
        Rs!SerialID = Right(String(FLength, "0") & _
                Trim(CStr(AddNo)), FLength)
        '¸ê®Æ§ó·s
        Rs.Update

    End Sub

    Private Sub Form_Load()
        Set Db = OpenDatabase("c:\user\mytest.mdb")
        Set Rs = Db.OpenRecordset("autonum", dbOpenDynaset)

        'Rs.EOF And Rs.BOF=True ªí¥Ü autonum Table ùØ©|¥¼¥[¤J¸ê®Æ
        If Not (Rs.EOF And Rs.BOF) Then
            '¨ú±o³Ì«á¤@µ§°O¿ýªº½s¸¹
            Rs.MoveLast
            '°²³] SerialID Äæ¦ì¬O¦Û°Ê½s¸¹¸¹Äæ¡A
            'Äæ¦ì«¬ºA Text
            AddNo = Rs!SerialID
        End If

        '²¾¨ì²Ä¤@µ§¥H§QÅã¥Ü
        Rs.MoveFirst
    End Sub

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

¦^¯Á¤Þ


¦ü¬O¦Ó«Dªº RecNo


³Ìªñ±`¦³¤H°Ý§Ú¥H«e Dbase ªº DBF Àɳ£¦³ RecNo °O¿ý½s¸¹¥i¥H°t¦X°O¿ý«ü¼Ð²¾°Ê¡A¬°¦ó Dao ª«¥óùؤ£´£¨Ñ«¨¡H¨ä¹ê¦b Recordset ª«¥ó©³¤U¡AÁÙ¬O¦³­ÓÃþ¦ü RecNo ÄÝ©Ê¥i¥H¥Îªº¡A¥s AbsolutePosition ¡A¤£¹L¥Î³oÄݩʦ³¤U¦C­­¨î¡G

  1. OpenRecordset ¬O¥Î dbOpenDynaset or dbOepnSnapshot ¼Ò¦¡¶}±Ò¤~¦æ¡C
  2. Recordset.AbsolutePosition ªº½d³ò ; 0 --> RecordCount-1¡C
  3. AbsolutePosition ©M¦­´Á Dbase ªº Recn ¤£¦P¡A¦b Dbase ¤¤¥u­n°O¿ý¨S¦³´¡¤J©Î§R°£¡ARecNo ¬O©T©wªº¡A¦ý Recordset.AbsolutePosition «o¬OÀHµÛ Recordset ¬d¸ß±ø¥ó¤£¦P¦Ó°ÊºA¤À°tªº¡A¤]´N¬O»¡§A¤£¯à¥ÎRecordset.AbsolutePosition ¥h§ä¨ì­ì Table ªº RecNo¡C
  4. ¦pªG§A¨âµ§°O¿ýªø±o¤@¼Ò¤@¼Ë¡A§A¥i¥HÀ˵ø¥¦­Ìªº AbsolutePosition ¨Ó§P§O¥¦­Ì¡C

¦^¯Á¤Þ


¦b VB ùØÀ£ÁY MDB ¸ê®Æ®w


ªG¥Ä ¼¶¼g©ó¤å³¹

¦p¦ó¼¶¼g¤@¬qµ{¦¡, §â¸ê®Æ®wÀ£ÁY??¦]¬°§Úµ{¦¡¥u¥Î¨ì¤@­Ó¸ê®Æ®w,§Q¥Îcompactdatabase³o­Ó¥\¯à, À£ÁYªº·sÂÂÀɦW¤£¯à¬Û¦P,§Úı±o«Ü©_©Ç, ·sÂÂÀɦW¤£¯à¬Û¦P?? ¨º§Ú·F¹À­n³o»ò¶O¤ßªº§â¥¦À£ÁY,

¦Ñ©Çµª¡G

  1. ´X¥G¤j³¡¥÷ªº¸ê®Æ®w¦b°µ ComPact ªº®É­Ô¡A³£¬O¥ý§â¸ê®Æ¿é¨ì¤@­Ó¼È¦sÀÉ¡A¦A§â¼È¦sÀÉÂл\­ìÀÉ¡AµM«á±þ±¼¼È¦sÀÉ¡C³o¬O¾AÀ³¸ê®Æ³B²z³t«×¤Î¯S®íµ²ºcªº¤@ºØ¤è¦¡¡A§A¤§©Ò¥H¤£ª¾¹D¸ê®Æ®w¬O³o¼Ë°Ê§@ªº¡A¬O¦]¬°¥H«e§A¥Îªº¸ê®Æ®w³nÅéÀ°§A¦Û°Ê°õ¦æ¤F¨º¨Ç¨BÆJ¡C
  2. §A°õ¦æ¤U¦Cµ{¦¡½X¡A´N·|±o¨ì©M Access ¸ê®Æ®wÀ£ÁY¬Û¦Pªº¥\¯à¤F¡C

DBEngine.CompactDatabase oldmdb, newmdb
FileCopy newmdb,oldmdb
Kill newmdb
(°õ¦æ¦¹µ{¦¡»Ý¥ý Close ¸ê®Æ®w)

¦^¯Á¤Þ


¥Î VB ¶} Excel Sheet ªí


jw86 ¼¶¼g©ó¤å³¹

½Ð°Ý¤£¥ÎDATA¤¸¥ó,¦p¦óOPEN¤@­ÓXLSÀÉ?set db=OpenDatabase("¸ê®Æ®w")¥u¯à¶}mdb,*.xlsÀÉ­n¦p¦ó¶}±Ò©O?

¦Ñ©Çµª¡G

Option Explicit
Dim Db As Database
Dim Rs As Recordset

Private Sub Form_Load()
    Set Db = OpenDatabase("c:\temp\book1.xls", False, False, "Excel 8.0;")
    Set Rs = Db.OpenRecordset("sheet1$")
'(SheetName «á­±¤@©w°O±o­n¥[ "$" ²Å¸¹)
End Sub

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

³o¬O³Ì²³æªº¿ìªk¡A¸Ô²Óªº¨Ï¥Î¤èªk¤Î­­¨î½Ð°Ñ¬Ý VB OnLineHelp ¡A¸ê®Æ¦s¨úª«¥ó¤â¥U¡B¨ú±o¥~³¡¸ê®Æ¡B¨Ï¥Î¸Õºâªí¤@³¹¡C

¦^¯Á¤Þ


¦^­º­¶

1