views:

53

answers:

1

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 database, it looks like it ONLY inserted the last field!

has anyone encountered this problem?

+3  A: 

EDIT: The code below works, but the corret solution can be found here: http://stackoverflow.com/questions/2829453/connecting-excel-to-mysql-update-problem/2829864#2829864

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
Remou