views:

81

answers:

3

i am connecting to a mysql database through excel using odbc

what does this line do?

Set rs = oConn.Execute("SELECT @@identity", , adCmdText)

i am having trouble updating the database:

   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

it is ONLY updating .Fields("instrument") = "NA", but for all other fields it is putting NULL values

+3  A: 

It selects (and returns) the last value inserted into an IDENTITY COLUMN in the current connection.

Here is reference material on the topic

http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html

Raj More
thank you raj, can you please give me an example?
I__
+1, it was important to note that it only works for `identity` columns
Daniel DiPaolo
can u answer the second part of the question please as well
I__
I think it is only adding the "N/A" because that is set as a default value in the column definition. You actually should create a new row and fill all the values in and then add the new row to the dataset and save.
Raj More
+1  A: 

It retrieves the identity of the last record you inserted into the database. See here: http://www.kamath.com/tutorials/tut007_identity.asp

Rice Flour Cookies
Actually, thanks for asking this question. I once asked the question of how to get the identity of the row I just inserted in another thread and received a number of responses telling me to declare a variable. I knew I had heard of `@@identity` somewhere!
Rice Flour Cookies
thank you rising star, can u answer the second part of the question please as well
I__
A: 

It retrieves the last inserted identity from an AUTO_INCREMENT column. However, I thought that LAST_INSERT_ID() was the proper function to use in MYSQL. I've never seen any reference to @@IDENTITY in the documentation. I thought it was only a SQL Server/Sybase construct.

Garett