Dim conn As New ADODB.Connection 'å建ä¸ä¸ª Connection å®ä¾ï¼å¨è¿é使ç¨Newçäºå°DimåSetå并为ä¸æ®µä»£ç æ§è¡
Dim rs As ADODB.Recordset 'å建ä¸ä¸ª Recordset å®ä¾ï¼ä¸ä½¿ç¨New æ¯å 为ï¼ç»å¸¸éè¦éå¤ä½¿ç¨Setï¼å æ¤æ²¡å¿
è¦å¨è¿é使ç¨
Dim CnStr As String, Sql As String 'å建两个å符串åéåå«åæ¾ä¸¤ä¸ªéåçSQLè¯å¥ä»£ç 段
1ãè£
è½½æ°æ®åº(ä¸å±äºRecordsetéå)
=============
Dim FileNamw$, DbIp$, DbName$, DbUser$, DbPw$
'以ä¸5个å符串åéåå«è¡¨ç¤ºæ件路å¾åæ件åãæ°æ®åºå°åãæ°æ®åºåãæ°æ®æä½åç¨æ·åãæä½åå¯ç
FileName = App.Path & "\'æ°æ®åºå'"
DbIp = "æ°æ®åºå°å"
DbName = "æ°æ®åºå"
DbUser = "æ°æ®æä½åç¨æ·å"
DbPw = "æä½åå¯ç "
'以ä¸åéæ ¹æ®æ°æ®åºç±»åçä¸åèä¸åï¼æå¯è½åªéè¦1è³ä¸¤ä¸ªåé
CnStr = "PROVIDER=microsoft.jet.oledb.3.51;persist security info =false;data source=" & FileName & ";Jet OLEDB:Database Password=" & DbPw
2ãRecordsetéåç常ç¨æ¹æ³
==========================
'1)æå¼ä¸ä¸ªè¡¨
'------------
Sql = "select * from 表å" 'SQLæ¥è¯¢è¯å¥
Set rs = New ADODB.Recordset 'æ°å»ºä¸ä¸ªå®ä¾
rs.Open Sql, conn 'ä½¿ç¨ Open æ¹æ³æå¼æ°æ®åºä¸çä¸ä¸ªè¡¨
'注æï¼è¿ç§æå¼æ¹å¼åªè½ä½¿ç¨ rs.MoveNext ï¼å³ï¼åå移å¨è¡åæ ï¼èä¸è½åå
¶ä»æ¹åï¼å¹¶ä¸ä¸è½ä¿®æ¹æ°æ®å
容
'
'rs.Open Sql, connï¼1 'è½ç¶åªå äºä¸ªâ1âï¼ä½è¿ç§æ¹æ³å¯ä»¥åä»»ä½æ¹å移å¨è¡åæ ã
'
'以ä¸åæ°ä»£è¡¨äºè¿ä¸ªå¯éå¼çå«ä¹
'0 = adOpenForwardOnly ï¼é»è®¤å¼ï¼æå¼ä»
ååç±»å游æ ã
'1 = adOpenKeyset æå¼é®éç±»å游æ ã
'2 = adOpenDynamic æå¼å¨æç±»å游æ ã
'3 = adOpenStatic æå¼éæç±»å游æ ã
'
'è½ç¶ä½¿ç¨ä»¥ä¸æ¹æ³å¯ä»¥å¯ä»¥å®ç°è¡åæ ï¼æ¸¸æ ï¼çä»»æ移å¨ï¼ä½æ¯ä»ç¶æ æ³åå
¥æ°æ®ãå æ¤éè¦è¿ä¸æ¥ç对Open æ¹æ³è¿è¡å®å
'rs.Open Sql, conn, 1, 3 'åé¢ç3æ¯ç¡®å®è¯»åæéç
'以ä¸åæ°ä»£è¡¨äºè¿ä¸ªå¯éå¼çå«ä¹
'1 = adLockReadOnly ï¼é»è®¤å¼ï¼åªè¯» â ä¸è½æ¹åæ°æ®ã
'2 = adLockPessimistic ä¿å®å¼éå®ï¼éä¸ªï¼ â å¨ç¼è¾æ¶ç«å³éå®æ°æ®æºçè®°å½ã
'3 = adLockOptimistic å¼æ¾å¼éå®ï¼éä¸ªï¼ â åªå¨è°ç¨ Update æ¹æ³æ¶æéå®è®°å½ã
'4 = adLockBatchOptimistic å¼æ¾å¼æ¹æ´æ° â ç¨äºæ¹æ´æ°æ¨¡å¼ï¼ä¸ç«å³æ´æ°æ¨¡å¼ç¸å¯¹ï¼ã
'
'2)读åæ°æ®
'----------
'å¢å ä¸è¡è®°å½å¹¶å¯¹æ°è®°å½çå
容è¿è¡ä¿®æ¹å¹¶ä¿åå¯ä»¥å¦ä¸åæ³
rs.AddNew 'å¢å ä¸è¡è®°å½
rs("...")="..." 'æ°æ®è¯»åæä½
...
rs.UpDate 'ä¿ååå
¥èµæï¼å¦æ使ç¨åªè¯»æéï¼åä¸è½ä½¿ç¨è¿ä¸ªæ¹æ³
rs.Close 'è¿ä¸ªæ¹æ³ç¨æ¥å
³éä½ æ代å¼ç表ï¼å¦æä¸ä½¿ç¨è¿ä¸ªæ¹æ³ä¹å¯ä»¥ï¼ä½æ¯æ°æ®åºä»ç¶è®¤ä¸ºä½ å¨å¯¹æ è¿è¡éå®ï¼å¯é ææ°æ®åºè´æ
è¿é
温馨提示:内容为网友见解,仅供参考