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

¦p¦ó¥ÎVB6³sµ²ACCESS¸ê®Æ®w¬d¸ß,·s¼W,§R°£,­×§ï©O?

¦p¦ó¥ÎVB6³sµ²ACCESS¸ê®Æ®w¬d¸ß,·s¼W,§R°£,­×§ï©O?

¥u­n·j´M¤@­ÓÄæ¦ì,¦p¤U¹Ï


§ÚªºÄæ¦ì¦p¤U¹Ï(access¸ê®Æ¬Ò¥Ñexcelªí®æ¶×¤J)


¦ý§Ú§Æ±æ¦b¼¶¼gªº®É­Ô¯à°÷§i¶D§Ú¦p¦óÅܳq
¨Ò¦p:¨­¤ÀÃÒ¦r¸¹¬O¦b²Ä5Äæ,
¦pªG§ï¤Ñ§Úªº¨­¤ÀÃÒ¦r¸¹¦b²Ä¤GÄ檺®É­Ô¤S¸Ó¦p¦ó§ï¼g.
Ãö©ó¸ê®Æ²Ä¤TÄ檺ªþ¥ó¥²¶·°µ¶W³sµ².(§Ú·í®É¦bexcel´N¦³°µ¦n,¥i±¤¤£·|³sµ²ªþ¥ó)
-----------------------------------¥i·Rªº¤À¹j½u--------------------------------------------

¤@¯ëÁpµ²¸ê®Æ®w¥u¦³Åã¥Ü¸ê®Æ,¨Ã¨S¦³·s¼W§R°£­×§ïªº¥\¯à,
§Ú§Æ±æ¯à°÷¨Ì·ÓÅv­­Àò±o·s¼W§R°£­×§ïªº¥\¯à



³Æµù:¦pªG¤À¹j½u¥H¤Uªº·s¼W,§R°£,­×§ï°µ¤£¥X¨Ó¥i¥H¼È®É©ñ±ó.

¥»©«³Ì«á¥Ñ vpower ©ó 2010-11-13 17:02 ½s¿è

½Ð°Ý¶Â·t¤j¤j¬O§âExcel·í§@VBªº¸ê®Æ®w¶Ü?

¦A¦¸·PÁÂ,¬Ý¨Ó§Ú¯uªº¸Ó¥[ªo¤F,§Ú§¹¥þ¬Ý¤£À´

§Ú¥ý¨Ó¥h¤U¸üVB2008¦n¤F,·P®¦

TOP

¦A¸É¥R¤@¤U  ³sµ²AccEss ªº°Ñ¼Æ

¸ê®Æ®w¸ô®| = "Z:\³¡ªù\»s³y¤¤¤ß\«~½èºÞ²z³¡\QM¸ê®Æ®w\FQCDataBase.mdb"
  mApp = "FQC"
  mApp1 = "ÀËÅç¤é´Á,ÀËÅç®É¶¡,¶g§O,¯Z§O,ÀËÅç¤H­û,¤u³æ¸¹½X,¼t°Ó¦WºÙ,²£«~½s¸¹,«~¦W,³W®æ,RUN¥d,¤j¼Ð,¤º¼Ð,¤p¼Ð,Hi-Pot,¥Ë¼Æ,ÀËÅçµ²ªG,²§±`Ãþ§O,²§±`¦ì¸m,²§±`½s½X,¤£¨}¶µ¥Ø,¤£¨}­ì¦],³B²z¤è¦¡,³Æµù"


mapp  ¬O table ªº¦WºÙ
mapp1  ¬O table  ªºÄæ¦ì¦WºÙ(¤£¬OÄæ¦ì¼Æ³á)
¬O¾Çµ{¦¡¦Ó¤£¬O­nµ{¦¡¡A¬O¶i¨Bªº°ò¦

TOP

¥t¥~  ³oÃäªO¤W¦³­Ó¸ê®Æ¬d¸ß   ¨º¸Ì¬O½׾ ¦³«Ü¦h¸ê®Æ  §A¥i¥H¥h¬Ý¬Ý
¥t  §A¥i¥H¸Õ¥Î  vb2008  ¤U¥h¼g¡A·|¤ñ  vb6ÁÙ¦n¼gªº¦h¤F
¬O¾Çµ{¦¡¦Ó¤£¬O­nµ{¦¡¡A¬O¶i¨Bªº°ò¦

TOP

Ãþ§O
clsADODBopenAcs
Option Explicit


Dim theCON As ADODB.Connection
Public theRST As ADODB.Recordset

Sub subConn(strFullName As String)
Dim strDrv As String

    strDrv = "Data Source=" & strFullName & ";"
    theCON.Open "rovider=Microsoft.Jet.OLEDB.4.0;" & strDrv & "Jet OLEDBatabase Password=zxcvbnm,./;"
   
   
   
    '¨ä±K½X°Ñ¼Æ¦p¦ó³]©w
'theCON.Open "rovider=Microsoft.Jet.OLEDB.4.0;" & strDrv & "Jet OLEDBatabase Password=yourpassword;"
   
End Sub

Sub subOpen(strCMn As String)
    theRST.Open Source:=strCMn, ActiveConnection:=theCON, _
                CursorType:=adOpenStatic, LockType:=adLockPessimistic, Options:=adCmdText
End Sub

Private Sub Class_Initialize()
    Set theCON = New ADODB.Connection
    Set theRST = New ADODB.Recordset
End Sub

Private Sub Class_Terminate()
    theCON.Close
    Set theRST = Nothing
    Set theCON = Nothing
End Sub


³o¬Oaccess ªºado ³s½uÃþ§O¡Aµ²¦X¤W¤@¬q¡A´N¥i¸ü¥X¸ê®Æ
¬O¾Çµ{¦¡¦Ó¤£¬O­nµ{¦¡¡A¬O¶i¨Bªº°ò¦

TOP

­Ó¤H«Øij¤£­n¥Î  adodb ¨º­ÓªF¦è¡A§Ú¤§«e¥Î¹L¤£«Ü¦n¥Î¡AÁöµM¥¦¬Y¨Ç¤è­±«Ü¤è«K¦ý¼u©Ê¤£¨¬

adoªº¸ê®Æ  ªO¤Wexcel µ{¦¡°Ï´N¦³¡A¤W¤å§Ú¦³´£¹L  excel¥i¥H¬Ý¦¨¸ê®Æ®w¡A¥Îªk¤@¼Ë  ¥u¬O¤Uªº°Ñ¼ÆÅܰʦӤw
¦p   http://forum.twbts.com/thread-556-1-1.html

¸Ì­±´N¦³§Úpoªºado  ³s½u

Dim theCON As ADODB.Connection
Public theRST As ADODB.Recordset

Sub subConn(strFullName As String)
  Dim strDrv As String
  Dim IQC_SQLPass$, IQC_SQLID$, IQC_SQLName$, IQC_SQLAdderss$
   (¤W­±¬O³sµ²¸ê®Æ®wªº¬ÛÃö¸ê°T ¦p ¸ê®Æ®w±K½X  ¸ê®Æ®wªí³æ   ¸ê®Æ®w¦WºÙ   ¸ê®Æ®w¦ì§})  


  IQC_SQLPass = "yyyyy"
  IQC_SQLID = "yy"
  IQC_SQLName = "Spc-Iqc"
  IQC_SQLAdderss = "192-168-100-199\SQLEXPRESS"
   
    theCON.Open "rovider=SQLOLEDB.1assword=" & IQC_SQLPass & "ersist Security Info=True;User ID=" & IQC_SQLID & ";Initial Catalog=" & IQC_SQLName & ";Data Source=" & IQC_SQLAdderss
   
End Sub

Provider=SQLOLEDB.1(³o­Ó§ï¦¨accessªº³s½u°Ñ¼Æ)   

³o¼Ë´N§¹¦¨  ¸ê®Æ®wªº³s½u¤F¡A¦A¨Ó´N¬O¸ò¸ê®Æ®w»¡¡A§Ú­Ì­n¤°»ò¤F
  1. Function ³sµ²AccEss(¸ê®Æ®w¸ô®| As String, mApp As String, mApp1 As String, Äæ¦ì¼Æ%)

  2. Dim strCMn As String
  3. Dim Ia%, Ib%
  4. Dim DArr(), Darr1
  5.   Set myDbAcs = New clsADODBopenAcs         '°_©l¤@­Ó·sªº³sµ²
  6.   strCMn = "select * from " & mApp    '³o¸Ìµ¹¤_SQL±Ô­z
  7.     With myDbAcs
  8.        .subConn ¸ê®Æ®w¸ô®|   '³sµ²¸ê®Æ®wÀɮצWºÙ(¥þ¸ô®|)
  9.        .subOpen strCMn        ' ¥Hµ¹¤_ªºSQL±Ô­z¥´¶}¤@­Ó¸ê®Æ¶°.
  10.     End With
  11.    
  12.     ReDim DArr(1 To myDbAcs.theRST.RecordCount, 1 To Äæ¦ì¼Æ)
  13.     Darr1 = Split(mApp1, ",", -1)
  14.       
  15.     For Ia = 1 To myDbAcs.theRST.RecordCount    'Ū¨ú¸ê®Æ
  16.       For Ib = 1 To Äæ¦ì¼Æ

  17.         DArr(Ia, Ib) = myDbAcs.theRST("" & Darr1(Ib - 1) & "").Value

  18.        ' myDbAcs.theRST.MoveNext
  19.       Next Ib
  20.       If Ia > 0 Then
  21.         myDbAcs.theRST.MoveNext
  22.       End If
  23.     Next Ia
  24.    
  25.    ³sµ²AccEss = DArr
  26.   
  27.    Set myDbAcs = Nothing   'ÄÀ©ñ³sµ²ª«¥ó
  28. End Function
½Æ»s¥N½X
¬O¾Çµ{¦¡¦Ó¤£¬O­nµ{¦¡¡A¬O¶i¨Bªº°ò¦

TOP

§Ú·j´M¤F¦³ÃöVB³sµ²ACCESS¸ê®Æ®wªº¸ê®Æ
VB¥i¥H©MAccess°µ³sµ²¡A¦ý¦³´X­Ó¨BÆJ­n³]©w¡A¦p¤U¡G

¤@¡D¶}±Ò·sªí³æ¡A¦b¥\¯àªí¦C"±M®×"¡÷"³]©w¨Ï¥Î¤¸¥ó"¡÷¿ïMicorsoft ADO Data Control6.0(OLEDB)¡A±NADODC1ªºª«¥ó©ñ¤Jªí³æ¤W¡C

¤G¡D¦bADODC1ªºª«¥ó¤W¡A«ö·Æ¹«¥kÁä¡A¿ïADODCªºÄÝ©Ê¡AµM«á·|¥X²{¤@­ÓÄÝ©Ê­¶ªºµøµ¡¡C¦bÄÝ©Ê­¶µøµ¡ªº"¤@¯ë"¶µ¥Ø¸Ì¡AÂI¿ï"¨Ï¥Î³s½u¦r¦ê"¡AµM«á«ö¥k¤èªº"«Ø¥ß"¶s«á¡A·|¦b¥X²{¤@­Ó¸ê®Æ³sµ²¤º®eªºµøµ¡¡C

¤T¡D¸ê®Æ³sµ²¤º®eµøµ¡ªº"´£¨ÑªÌ"¶µ¥Ø¸Ì¡A¿ï¨ú"Microsoft Jet 4.0 OLE DB Provider"¡A«ö"¤U¤@¨B"¡A¸ê®Æ³sµ²¤º®eµøµ¡·|¤Á´«¨ì"³s½u"¶µ¥Ø¸Ì¡AµM«á¦b"1.¿ï¾Ü©Î¿é¤J¸ê®Æ®w¦WºÙ"¤U¤èªÅ¥Õ³B¿é¤J­n³sµ²ªºAccessÀɮצWºÙ¤Î¸ô®|¡A¤]¥iª½±µ«ö¥k¤èªº"..."Áä¥h¥[¤JÀɮסAÀÉ®×¥[¤J«á«ö¤U¤è"´ú¸Õ³s½u"¶s¡A¦pªG¥X²{´ú¸Õ³s½u¦¨¥\ªºµøµ¡¡A´Nªí¥ÜVB©MAccessªºÀɮפw¸g³sµ²¤F¡A«ö"½T©w"¶s¦^¨ìÄÝ©Ê­¶ªºµøµ¡¡C

¥|¡D¦bÄÝ©Ê­¶µøµ¡ªº"¸ê®Æ¿ý¨Ó·½"¶µ¥Ø¸Ì¡A©R¥OÃþ«¬½Ð¿ï¾Ü"2-adCmd Table"¡A¸ê®Æªí©Î¹w¦sµ{§Çªº¦WºÙ½Ð¿ï¾Ü§AAccessÀɮפºªº¸ê®Æªí¦WºÙ¡]³q±`¥u·|¦³¤@­Ó¦Ó¤w¡AAccessªº¤º©wÀɦW¬O"¸ê®Æªí1"¡A°£«D§AªºAccess¦³°µ¤G­Ó¸ê®Æªí¡^«ö"½T©w"¶s¡C

¤­¡D¦bªí³æ¤W©ñ¤JText1,Text2,Text3ª«¥ó¡A±N³o¤T­Óª«¥óªºÄÝ©ÊDataSource¿ï¾Ü"Adodc1"¡AµM«á¦A±NText1ªºÄÝ©ÊDataField¿ï¾Ü"¾Ç¸¹"¡AText2ªºÄÝ©ÊDataField¿ï¾Ü"°ê¤å"¡AText3ªºÄÝ©ÊDataField¿ï¾Ü"¼Æ¾Ç"¡C

¤»¡D°õ¦æµ{¦¡¡AAccessªº¸ê®Æ´N·|Åã¥Ü¦bText¤W¤F¡C

PS¡GAccess¸ê®ÆªíªºÄæ¦ì¦WºÙµLªkŪ¶iText¸Ì¡A§A­n¦Û¤v¥ÎLabel¥h¼Ð¥Ü¡C

¥H¤W³o­Ó¹ï§Ú­n§¹¦¨ªº¸ê®Æ¬O§_¦³¥Î©O?

TOP

¥»©«³Ì«á¥Ñ vpower ©ó 2010-11-13 11:15 ½s¿è

¯uªº«D±`·PÁ¨â¦ì¤j¤j,§Ú¥ý¥h¬Ýadoªº¥Îªk¦n¤F,§Æ±æ¥i¥H¦b¬P´Á¤@¥H«e§¹¦¨.

·t¶Â¤j¤j±z¦n
¬O§_¥i¥H´£¨Ñ´X­Óºô¯¸©O?§Ú§ä¤F¦n¤[³£¨S¦³ado±qÀY¨ì§À¾Þ§@ªº¸Ñ»¡.

et5323 ¤j¤j±z¦n
·Q½Ð±Ð±z¤@¤U"¨Ï¥Î¤èªk
1.¦bPersonal_ID:¥k¤è¿é¤JH
2.«ö¤ULookUp
3.¥L·|Åã¥Ü¿ù»~,¦p¤U
    adoRecordset.Open sSQL, adoConnection, 1, 1
³o¬O¤°»ò·N«ä©O?
ShowDoc¬O§_¶}©l¸Óµ§¸ê®Æªº¶W³sµ²©O?

TOP

ªþ¥ó¬O¤@个³Ì°ò¥»ªºVB6.0°µ«e¥x¬É­±¡A³q过ADO连±µ¦Z¥xAccess数Õu库ªº单É󪩮ୱ¨t统¡A¥u¬O§¹¦¨¤F¬d询¥\¯à¡C­Y§A对ADO©MSQL¤£¼ô±xªº话¡A§A©Ò­n¨Dªº¨ä¥¦·s¼W,§R°£,­×§ï¥\¯à§A¬O°µ¤£¥X来ªº¡C
¥Ñ¤_¨t统¦rÊ^ªº缘¬G¡A¥N码¥¼§@¸Ñ释¡A写¤F§A¥´开¤]¬O乱码¡C
vb6.rar (31.4 KB)

TOP

¨ä¹ê¤£·|«Ü½ÆÂø¡A¤@­Ó¥\¯à¤@­Ó¥\¯à§é¶}¨Ó·Q´N¦n¤F
¥t¥~...§Ú¼gªº¬O¬[ºc¥u­n¨Ì¬[ºc¤U¥h¡A´N¤@©w°µªº¥X¨Ó

¸ê®Æ®w  <<>>  ado³s½u  <<>>  sql  »yªk    ´N¥i¥H¹F¦¨Äæ¦ì¦W  ©Î  Äæ¦ì¼Æ
(excel¤]¥i¥H¬Ý¦¨¬O¸ê®Æ®w)¡A§A¥i¥H¥h¬Ý¤@¤U  ado ªº¥Îªk¡AªO¤W¦³

µn¤J
§AÀ³¸Ó¥ý«Ø¥ß¤@­Ótable(¸ê®Æ®w)¡A°O¿ý  user  password   add  del  updata
                                                       001      1234         y      n      y
³o¼Ëªº¤è¦¡  §Ú¦b µn¤J form ®É  ¨Ï¥ÎªÌ¿é¤J  ±b±K  «ö¤U  ½T©w®É¡A
   ¥Îado  ³s½u  §ä¥X   user¡AµM«á¦^¶Ç  ¤ñ¹ïpasswod¡A  ok®É  ±a¤JÅv­­

±N  add  del  updata  ¥Î  °}¦C°O¿ý°_¨Ó¡A  form1    ¦b  load  ®É¡A§P©w  add = y ®É
·s¼W¶s.enabled=true      §R°£¶s.enabled=false
³o¼Ë´N¥i¨Ì¨Ï¥ÎªÌ¡A¥h¨M©w¨Ï¥Îªº¥\¯à

·íµM  ¼gªk¯uªº¦³«Ü¦hºØ¡A§Ú¦C¥Xªº¥u¬O«Ü²³æªº¤@ºØ¡Aºô¤W¯uªº¦³«Ü¦h¸ê®Æ
¥t  ­n¹ï¸ê®Æ®wÀ³¥Î  ¯uªº­n·|  ³s½u¤è¦¡ ¡A ado ¬O¤@ºØ±`¥Îªº¥Îªk  ¡A«Øij¥h§ä¤@¤U¬ÛÃö¸ê®Æ¡A¤£·|ado  ¸ê®Æ®w¦s¨ú¥\¯à¡A­Ó¤Hıªº·|¤Ö¤@¥b

¥t  sql »yªk  °t¦Xado   ¤~¯à¤U©p­nªº±ø¥ó¡A¤]´N¬O»¡¡Aado  ¬O  vb  ¸ò ¸ê®Æ®wªº¾ô¼Ù   sql   ¬O§Aªº»Ý¨D
©Ò¥H  ado  ¸òsql   ¬O¤£¥i¤Öªº

¶W³sµ²ªº³¡¥÷¡A   ·í§A§â¬d¸ß­È  ¦^¶Ç¦^¨Ó«á¡A ¦A¹ï  ¯S©wªºÄæ¦ì¡A¥h«ü©w¬°¶W³sµ²(©Î¥Î¶W³sµ²¤¸¥ó)

©Ò¥H  ·í  °õ¦æ§¹  ¥H¤Wªºµ{¦¡¬q  ¨Ï¥ÎªÌ¬Ý¨ìªº  ´N¬O§¹¾ãªº¥\¯à¤F

§A¥i¥H¸Õ¸Õ¬Ý¦A°Ý  §A¹J¨ìªº°ÝÃD¡A­n¤£µM³o¼Ë¾ã½g»¡¡A¯uªº·|¼g«Ü¦h«Ü¤[¡A§Ú¥u¦n¤j´nªº»¡¤@¤U
¥t  «Øij §A¥ý¬Ý¤@¤U  ado   §O¤Hªº¥Îªk  (¸Ì­±·|¦³sqlªº¥Îªk¡A¤£À´¦A°Ý)
¸Õ¸Õ§a
¬O¾Çµ{¦¡¦Ó¤£¬O­nµ{¦¡¡A¬O¶i¨Bªº°ò¦

TOP

        ÀR«ä¦Û¦b : §Ú­Ì³Ì¤jªº¼Ä¤H¤£¬O§O¤H¡D¥i¯à¬O¦Û¤v¡C
ªð¦^¦Cªí ¤W¤@¥DÃD