I am working on a transaction website. When a subscription is created the modified date is inserted in the table. What I am trying to accomplish is to uniquely identify that record. Here is that I am trying:
DateTime currentTime = DateTime.Now;
Debug.WriteLine("Current Timestamp is: " + currentTime.ToString("yyyy-MM-dd HH:mm:ss:fff"));
sCmd.CommandText = "SELECT distinct userID FROM table WHERE Report_OID = @reportID AND ModifiedDate = @currentTime";
sCmd.Parameters.AddWithValue("@reportID", reportID);
sCmd.Parameters.AddWithValue("@currentTime", currentTime.ToString("yyyy-MM-dd HH:mm:ss:fff"));
Output:
Current Timestamp is: 2016-06-09 10:19:16:586
Modified Date is: 2016-06-09 10:19:16.553
Tried this:
sCmd.CommandText = "SELECT LAST_INSERT_ID();";
IDataReader reader = sCmd.ExecuteReader();
while (reader != null && reader.Read())
{
long lastInsertedID = reader.GetInt64(0);
Debug.WriteLine("return id is : " + lastInsertedID);
}
Got this error:
'LAST_INSERT_ID' is not a recognized built-in function name.
This error may have happened due to the createSubscription method call to create a subscription in the reporting service webservice which handles the insert in the database. I do not have insert statements in my code.
This will fail as the milliseconds wont be the same. The reason I want to use milliseconds is to prevent multiple userids if two users insert a subscription around the same time.
What I am trying to figure out is compare these two dates so I can accurately get the userID of my transaction and not worry about grabbing someone else user id if two transactions are inserted at the same time. Is this possible? Am I trying to solve this the wrong way. Any help will be appreciated. Thank you.
Aucun commentaire:
Enregistrer un commentaire