我連接到MySQL表通過Excel VBA中,我更新它:連接的Excel到MySQL更新問題
Set cn = New ADODB.Connection
cn.Open "DRIVER={MySQL ODBC 5.1 Driver};" & _
"SERVER=localhost;" & _
"DATABASE=employees;" & _
"USER=root;" & _
"PASSWORD=M1llen;" & _
"Option=3"
'lets get the batch info
'
' open a recordset
Set rs = New ADODB.Recordset
rs.Open "batchinfo", cn, adOpenKeyset, adLockOptimistic, adCmdTable
' all records in a table from Report 1
'Set wsSheet1 = wbBook.Worksheets(1)
' better refer by name
'Set wsSheet1 = wbBook.Worksheets.("Report 1")
Worksheets.Item("Report 1").Select
dpath = Range("B2").Text
atime = Trim(Range("B3").Text)
rtime = Trim(Range("B4").Text)
lcalib = Trim(Range("B5").Text)
aname = Trim(Range("B6").Text)
rname = Trim(Range("B7").Text)
bstate = Trim(Range("B8").Text)
instrument = GetInstrFromXML()
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("datapath") = "abc"
.Fields("analysistime") = atime
.Fields("reporttime") = rtime
.Fields("lastcalib") = lcalib
.Fields("analystname") = aname
.Fields("reportname") = rname
.Fields("batchstate") = bstate
.Fields("instrument") = instrument
.Update ' stores the new record
End With
的問題是,那個被更新的唯一領域是儀器領域!
這裏91A的batchinfo表的mysql的說明:
mysql> desc batchinfo;
+--------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------+------+-----+---------+----------------+
| rowid | int(11) | NO | PRI | NULL | auto_increment |
| datapath | text | YES | | NULL | |
| analysistime | text | YES | | NULL | |
| reporttime | text | YES | | NULL | |
| lastcalib | text | YES | | NULL | |
| analystname | text | YES | | NULL | |
| reportname | text | YES | | NULL | |
| batchstate | text | YES | | NULL | |
| instrument | text | YES | | NULL | |
+--------------+---------+------+-----+---------+----------------+
9 rows in set (0.00 sec)
有趣的是,當我重新創建表,而不AUTO_INCREMENT然後正常工作
我真的需要有人來回答這個問題,我不關心,如果你有一種預感,或者不是很確定,我會嘗試任何解決方案
請,請,請不要不斷地問同樣的問題,一遍又一遍。只需編輯您的原始問題。雖然我喜歡Excel和VBA問題,但VBA用戶數量並不龐大。你可以嘗試一些其他的VBA論壇。 – 2010-05-13 19:37:49