Solved

C++ Builder ODBC How to set the CURRENT_TIMESTAMP in SetFields method?

Posted on 2009-05-05
4
686 Views
Last Modified: 2013-11-17
I am using an ADODataSet object in C++ Builder 6, and using the SetFields and Post methods to set the values of the fields in the table, and insert the record into it. The last field in the table is a DateTime field. The current version of the code (below) works, but its putting the local PC time into the table records. I want to use CURRENT_TIMESTAMP instead, to store the database server time. I tried just using the constant (like SQL_FN_TD_CURRENT_TIMESTAMP), I tried it as an AnsiString, both return an exception in the SetFields call. How do I do this?

Thanks,
Tod
TADODataSet *dataset = frmADO->ADODataSet11;
         AnsiString dt;
         DateTimeToString(dt, "mm/dd/yyy hh:mm:ss", Now());
         try
            {
            dataset->SetFields(ARRAYOFCONST((crData.Conn_ID_C, crData.CSC_Site_C,
                                             crData.Operator_ID_C, crData.Term_ID_C,
                                             crData.WU_DNIS_No_C, crData.WU_Call_Reason_CD_N,
                                             crData.WU_Additional_Info_C, crData.Caller_Lang_CD_N,
                                             crData.Caller_Type_C, crData.WU_Product_ID_C,
                                             crData.Cap_Type_C, crData.Comments_C,
                                             crData.Skill_CD_C, t, TVarRec(dt))));

Open in new window

0
Comment
Question by:todgor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 2

Expert Comment

by:Morris_Szyslak
ID: 24313935
What kind of exception do you get?

You could try "Now()", this should put the current date and time of the server.
0
 

Author Comment

by:todgor
ID: 24317782
I tried "Now()" and "fn Now()" as ANSIString variables like this:

   AnsiString dt = "Now()";  

   dataset->SetFields(ARRAYOFCONST((crData.Conn_ID_C, crData.CSC_Site_C,
                                  crData.Operator_ID_C, crData.Term_ID_C,
                                  crData.WU_DNIS_No_C, crData.WU_Call_Reason_CD_N,
                                  crData.WU_Additional_Info_C, crData.Caller_Lang_CD_N,
                                  crData.Caller_Type_C, crData.WU_Product_ID_C,
                                  crData.Cap_Type_C, crData.Comments_C,
                                  crData.Skill_CD_C, t, TVarRec(dt))));

But I got the same type of exception, which is "Program xxxx raised exception EConvertError with message "Now() is not a valid date and time". Process stopped." Is it used as some other data type? Am I able to run functions from the database server like this?
0
 
LVL 2

Accepted Solution

by:
Morris_Szyslak earned 500 total points
ID: 24323352
Apparently not, sorry. I was wrong about how the SetFields() method works. I thought it would run a command on the sql server but it only changes the data set and runs a command when you Post() the dataset. It seems the dataset locally stores the values in the format that is specified in the FieldDefs.

You could try to set the FieldDef to ftString and after that call SetFields();
dataset->FieldDefs->Items[insert index of the datetime field]->DataType = ftString;
I'm not sure if this will work, but it may be worth a try

You could also build a SQL command and give the parameters as you like. But you might have to change the structure of your app for this.
0
 

Author Closing Comment

by:todgor
ID: 31578271
I tried working with the ADOQuery object to build a SQL command, but I found it cumbersome. I ended up issuing a select to retrieve the server date-time to use in  the Post
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
error when compiling my project in eclipse luna 30 537
HTML/Webpage Editor for Windows 10 20 193
How to format date and time in Eclipse IDE comments 2 114
debug as  junit test 4 88
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question