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

[µo°Ý] ¤Þ¥Îado cmdªºexecute¤èªk¥¢±Ñ

[µo°Ý] ¤Þ¥Îado cmdªºexecute¤èªk¥¢±Ñ

¦U¦ì¤j¤j¦n¡G
¤p§Ì·Q¤Þ¥Îadodb command»yªk¨Ó°õ¦æ
§ó·s¸ê®Æ®wÄæ¦ì¸ê®Æ¡A¦ý¥X²{»yªk¿ù»~¦p¤U¡G
°õ¦æ¶¥¬q¿ù»~-2147217904 (80040e10)
µL­È´£¨Ñµ¹¤@©Î¦h­Ó¥²­n°Ñ¼Æ
»yªk¦p¤U¡G
  1. Sub mm()
  2.    
  3. Dim cmdCommand As New ADODB.Command
  4. Dim recSet As New ADODB.Recordset
  5. Dim cn As New ADODB.Connection
  6. Dim code, dateSold As String
  7. Dim conStr As String, mFile As String, strSQLCommand As String

  8. mFile = "D:\TEMP\EX6.mdb"
  9. conStr = "Provider=Microsoft.jet.oledb.4.0;Data Source=" & mFile
  10. cn.ConnectionString = conStr
  11. cn.Open

  12. cmdCommand.ActiveConnection = cn
  13.   code = 5
  14.   dateSold = "¦n³Ü¨F¤h"
  15.   strSQLCommand = "UPDATE tb²£«~2A SET ³æ¦ì¼Æ¶q='1200' WHERE ((²£«~½s¸¹)=" & code & ") AND ((²£«~¦WºÙ)=" & dateSold & ") "
  16.   cmdCommand.CommandText = strSQLCommand
  17.   cmdCommand.CommandType = adCmdText
  18.   Set recSet = cmdCommand.Execute
  19.   
  20. End Sub
½Æ»s¥N½X
test-b1.rar (6.39 KB)

¦^´_ 1# dechiuan999
  1. dateSold = "'¦n³Ü¨F¤h'"
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 2# GBKEE

ª©¥D¤j¤j±z¦n¡G

ÁÂÁ±z¡C
¤p§Ì¨Ìª©¥D¤j¤j´£¨Ñªº¤è¦¡¡A
°ÝÃD¤w§JªA¡C¤p§Ì¤w©¹«eÁÚ¥X
¤@¤j¨B¡C¦ý¤ß¸ÌÁÙ¬O¦s¦³ºÃ´b
¡A±æª©¥D¤j¤j¯à¦A¶}ÄÀ¡C
ºÃ°Ý¤@¡G
code=5¬°¦ó¤£¶·¥[³æ¤Þ¸¹
¦ÓdateSold = "'¦n³Ü¨F¤h'"
¶·¥[³æ¤Þ¸¹¤£ª¾¦³¦ó®t²§¡C
ºÃ°Ý¤G¡G
¤p§Ì­ì¬O¤Þ¥Îado recordset
¨Ó§ó·s¸ê®Æ®wÄæ¦ì¸ê®Æ¡A¦ý¹J
¨ìmysql¦n¹³¤£¬O¯à§¹¥þ¤ä´©¡C
¦]¦¹¡A·Q¹Á¸Õ§ï¥Î¦¹¤èªk¡C
¦ý¤p§ÌªººÃ´b¬O¦p¨Ì¦¹´NµLªk
¨Ï¥Îsql»yªkÁY¤p­n§ó·s½d³ò
¤Î°õ¦ærecordset¨Ãª½±µ§¹¦¨§ó·s¡C
¦Ó¥Ø«eexcel¸ê®Æªí¨C¤@¶µ¦¸¬O
³v¶µ¤Þ¥Îexecute¨Ó°õ¦æ¡C
³o¼Ë¬O§_«Ü¤£¾A·í¦Ó¦³¥t¤@¤è
ªk¨Ó

TOP

¦^´_ 3# dechiuan999
§Ú¨S¦³¨Ï¥Î¹L¸ê®Æ®w³nÅé
¸ê®Æ®wªº¨Ï¥Î¤j¦P¤p²§.ªþÀɬOºô¸ô¤W¤U¸üªº¥i°Ñ¦Ò¤@¤U.

Ex.rar (210.96 KB)
  1. Option Explicit
  2. Sub Ex()
  3.     '¤Þ¥Î Microsoft DAO 3.0 Object Libiary
  4.     Dim myData As String, myTable As String, SQL As String
  5.     Dim myDb As DAO.DataBase
  6.     Dim myRs As DAO.Recordset
  7.     Dim i As Integer
  8.     Dim code, dateSold
  9.     ActiveSheet.Cells.Clear          '²M°£¤u§@ªíªº¥þ³¡¸ê®Æ
  10.     myData = "D:\TEMP\EX6.mdb"
  11.     Set myDb = OpenDatabase(myData)
  12.     code = 5                '¸ê®ÆªíªºÄæ¦ì FieldType ¬OdbSingle' 6
  13.     dateSold = "'¦n³Ü¨F¤h'" '¸ê®ÆªíªºÄæ¦ì FieldType ¬O dbText '10
  14.     SQL = "UPDATE tb²£«~2A  SET ³æ¦ì¼Æ¶q=88 WHERE ((²£«~½s¸¹)=" & code & ") AND ((²£«~¦WºÙ)=" & dateSold & ") "
  15.     myDb.Execute (SQL)   '
  16.     SQL = "select * from tb²£«~2A  WHERE ²£«~½s¸¹<=" & code
  17.     Set myRs = myDb.OpenRecordset(SQL)
  18.     If myRs.RecordCount > 0 Then
  19.         For i = 1 To myRs.Fields.Count  '½Æ»sÄæ¦ì¦W
  20.            Cells(1, i) = myRs.Fields(i - 1).Name
  21.         Next i
  22.         '³]¸mÄæ¦ì¦W¦rÅ鬰¥[²Ê¨Ã©~¤¤¹ï»ô
  23.         With Range(Cells(1, 1), Cells(1, myRs.Fields.Count))
  24.             .Font.Bold = True
  25.             .HorizontalAlignment = xlCenter
  26.         End With
  27.         Range("A2").CopyFromRecordset myRs '½Æ»s¥þ³¡¸ê®Æ
  28.     End If
  29. 'Ãö³¬°O¿ý¶°¤Î¸ê®Æ®w³s±µ , ¨ÃÄÀ©ñÅܼÆ
  30. myRs.Close
  31. myDb.Close
  32. Set myRs = Nothing
  33. Set myDb = Nothing
  34. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 4# GBKEE

ª©¥D¤j¤j±z¦n¡G

    Åýª©¥D¤j¤j³Ò¤ß¤F¡C
¤p§Ì¤w¥ý¤U¸ü¦¬ÂáA
¤]·|¦n¦n¬ã¨s¥¦¡C

´N·P®¦¡I

TOP

        ÀR«ä¦Û¦b : ¤Ñ¤W³Ì¬ü¬O¬P¬P¡A¤H¥Í³Ì¬ü¬O·Å±¡¡C
ªð¦^¦Cªí ¤W¤@¥DÃD