开发者

why is ADODB inserting NULL values on update?

开发者 https://www.devze.com 2022-12-29 22:21 出处:网络
i have: With rs .AddNew \' create a new record \' add values to each field in the record .Fields(\"datapath\") = dpath

i have:

With rs
    .AddNew ' create a new record
    ' add values to each field in the record
    .Fields("datapath") = dpath
    .Fields("analysistime") = "atime"
    .Fields("reporttime") = "rtime"
    .Fields("lastcalib") = "lcalib"
    .Fields("analystname") = "aname"
    .Fields("reportname") = "rname"
    .Fields("batchstate") = "bstate"
    .Fields("instrument") = "NA"
    .Update ' stores the new record
End With

when i check the datab开发者_Python百科ase, it looks like it ONLY inserted the last field!

has anyone encountered this problem?


EDIT: The code below works, but the corret solution can be found here: Connecting Excel to Mysql Update PROBLEM

It involves the difficulties of using text data type.


This seems to work, but don't ask me why:

dpath = "a" ''Trim(Range("B2").Text)
atime = "a" ''Trim(Range("B3").Text)
rtime = "a" ''Trim(Range("B4").Text)
lcalib = "a" ''Trim(Range("B5").Text)
aname = "a" ''Trim(Range("B6").Text)
rname = "a" ''Trim(Range("B7").Text)
bstate = "a" ''Trim(Range("B8").Text)

cn.Open strCon
cmd.ActiveConnection = cn
cmd.CommandText = _
    "INSERT INTO `batchinfo` (`datapath`, `analysistime`," _
       & "`reporttime`,`lastcalib`,`analystname`,`reportname`," _
       & "`batchstate`,`instrument`) " _
       & "VALUES (?,?,?,?,?,?,?,?);"

cmd.Parameters.Append _
    cmd.CreateParameter("datapath", adChar, adParamInput, 100)
cmd.Parameters.Append _
     cmd.CreateParameter("analysistime", adChar, adParamInput, 100)
cmd.Parameters.Append _
     cmd.CreateParameter("reporttime", adChar, adParamInput, 100)
cmd.Parameters.Append _
     cmd.CreateParameter("lastcalib", adChar, adParamInput, 100)
cmd.Parameters.Append _
     cmd.CreateParameter("analystname", adChar, adParamInput, 100)
cmd.Parameters.Append _
     cmd.CreateParameter("reportname", adChar, adParamInput, 100)
cmd.Parameters.Append _
     cmd.CreateParameter("batchstate", adChar, adParamInput, 100)
cmd.Parameters.Append _
     cmd.CreateParameter("instrument", adChar, adParamInput, 100)

cmd.Parameters("datapath").Value = "abc"
cmd.Parameters("analysistime").Value = atime
cmd.Parameters("reporttime").Value = rtime
cmd.Parameters("lastcalib").Value = lcalib
cmd.Parameters("analystname").Value = aname
cmd.Parameters("reportname").Value = rname
cmd.Parameters("batchstate").Value = "bstate"
cmd.Parameters("instrument").Value = "NA"

cmd.Execute
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号