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

[µo°Ý] ADO - SQL ¨ú±oÄæ¦ì¤º ¤£­«ÂÐ­È ¨Ã±Æ°£ ªÅ­È

[µo°Ý] ADO - SQL ¨ú±oÄæ¦ì¤º ¤£­«ÂÐ­È ¨Ã±Æ°£ ªÅ­È

¥»©«³Ì«á¥Ñ ·t¶Â ©ó 2010-6-11 17:06 ½s¿è

½Ð±Ð¦U¦ì¤j¤j
  ADO  SQL  ªº»yªk
   ¸ê®Æªí  A
   Äæ¦ì¦WºÙ¡G1 ,2 , 3
§Ú¤UªºSQL»yªk  ¦p¤U

1. ¤£²z·|ªÅ­È
    Select Distinct 2 Form A
   µ²ªG¡Gªð°j­È  ¬°-1   

2. ±Æ°£ªÅ­È
    2.1  Select Distinct 2 Form A Where 2<>''
        µ²ªG¡G¿ù»~
    2.2   Select Distinct 2 Where 2<>'' Form A
        µ²ªG¡G¿ù»~

½Ð°Ý¦U¦ì¤j¤j¡A«ü¾É¤@¤U¡A»yªk­n¦p¦ó¤U¡A§Ú½T©w¸ê®Æ®w¤º¬O¦³¸ê®Æªº¡A´N¬OµLªk¿z¥X¡A½Ð«ü¾É

§Ú¬d¤F¤@¤Uado  ¦^ÂÐ
  1. underlyingVale:¥Ø«e´£¨ÑªÌ¤£¤ä´©­«·s¾ã²z°ò©³­È
  2. LockType:adLockReadOnly   (¥i¬O§Ú¬O¤ULockType:adLockPessimistic)
  3. OriginalValue:¥Ø«eªº¸ê®Æ¿ý¶°¤£¤ä´©§ó·s¡C³o¥i¯à¦¨¬°´£¨ÑªÌ©Î©Ò¿ï©wÃþ«¬ªº­­¨î

¥i¬O §ÚÁÙ¬O¤£ª¾¹D°ÝÃD¦b¨º¡A½Ð¦U¦ì¥ý¶i«ü¾É¤@¤U
¬O¾Çµ{¦¡¦Ó¤£¬O­nµ{¦¡¡A¬O¶i¨Bªº°ò¦

§ä¨ì¤F...
¦] ¨Ï¥Î Distinct   ¬°¦^¶ÇºA¬°°ßŪ­È¡A¬G ado LockType ­n¨Ï¥Î adLockReadOnly
.theRST.RecordCount   ¡A¤~·|¦^¶Çµ§¼Æ
1

µû¤À¤H¼Æ

    • ¤p»x: ¦Û§U¦Ó«Dµ¥«Ý¤H§U,¬°§Aªººë¯«¥[¤Àª÷¿ú + 1
¬O¾Çµ{¦¡¦Ó¤£¬O­nµ{¦¡¡A¬O¶i¨Bªº°ò¦

TOP

¥»©«³Ì«á¥Ñ ·t¶Â ©ó 2010-6-14 11:40 ½s¿è

­è­è  ¥Î  excel 2003 ¤@¼Ò¤@¼Ë  ªºµ{¦¡  ¤U¥h°õ¦æ¡Aµ²ªG ¸ê®Æ¬O¦³¦^¶Çªº

½Ð°Ý¦U¦ì¤j¤j¡G
myDbSqlSpcIqc.theRST.RecordCount    À³¸Ó¬O¦^¶Ç¸ê®Æµ§¼Æ(88µ§)¡Aµ²ªG¦^¶Ç­È¬O-1¡A³o¬O¤°»ò°ÝÃD©O¡A¬O§Úado¼Ò¦¡¦³°Ý¬O  ÁÙ¬O...

ps:  adoµ{¦¡¬q§Ú¬O¼g¼Ò²Õªº¼Ò¦¡¡A³o­Óado ¤w³Q°õ¦æ¦h¦¸¡A¥u¦³  sql  ¤U  Distinct  ®É¦³°ÝÃD

¶Ç»¼­È¡G
strCMn="select Distinct ¥[¤u¼t°Ó from °U¥~_¥b¦¨«~"

ado µ{¦¡¬q

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$
   
  IQC_SQLPass = "yyyyy"
  IQC_SQLID = "yy"
  IQC_SQLName = "Spc-Iqc"
  IQC_SQLAdderss = "192-168-100-199\SQLEXPRESS"
   
    theCON.Open "Provider=SQLOLEDB.1;Password=" & IQC_SQLPass & ";Persist Security Info=True;User ID=" & IQC_SQLID & ";Initial Catalog=" & IQC_SQLName & ";Data Source=" & IQC_SQLAdderss
   
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¾Çµ{¦¡¦Ó¤£¬O­nµ{¦¡¡A¬O¶i¨Bªº°ò¦

TOP

        ÀR«ä¦Û¦b : ¬°¦Û¤v§äÂǤfªº¤H¥Ã»·¤£·|¶i¨B¡C
ªð¦^¦Cªí ¤W¤@¥DÃD