Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateTimePicker problem

Status
Not open for further replies.

ik0

Programmer
Jun 2, 2010
14
MK
How to write the value of DateTimePicker in database, and after that value to read from the database. Using ADOQuery and C++ Builder 2009.

picture:
34y3ct3.png


I apologize to grammatical errors.
 
How is the date stored in the data base? Is it a string, date, or date/time value?


James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
So 2ffat was focusing on the format of the date or date/time string. That is the first thing on which you need to focus.


After you have determined the correct format, how are generating the INSERT/UPDATE SQL query? Are you concatenating the query in code or are you using parameters?

Steve.
 
date stored is string. After that value will need to read from the database. If there in the base the date is 19.02.1999 then the same value needed to be writlen in database.
 
OK. That's a start. To convert a TDateTime to a string, you have several options. I like to use AnsiStrings since most of my code was written prior to Unicode. For example, suppose my DateTimePicker is named "MachineDateTimePicker." I could do something like:
Code:
TDate MachineDate = MachineDateTimePicker->Date;
AnsiString MachineDateStr = MachineDate.FormatString("dd'-'mm'-'yyy");

Next you need to consider Smay's question. The following example uses an ADOQuery named "TimeADOQuery." You could do something like:
Code:
// Set up Add
AnsiString ProdSQLAddStr = "INSERT INTO ProductionHours ";
ProdSQLAddStr += "(Machine, MachineDate, MachineShift, MachineTtlHours) VALUES(";
ProdSQLAddStr += "'" + MachineStr + "', ";
ProdSQLAddStr += "'" + MachineDateStr + "', ";
ProdSQLAddStr += "'" + MachineShiftStr + "', ";
ProdSQLAddStr += "'" + ProdHoursStr + "')";

try                     // Process
{
    TimeADOQuery->Close();
    TimeADOQuery->SQL->Clear();
    TimeADOQuery->SQL->Add(ProdSQLAddStr);
    TimeADOQuery->Prepared = true;
    TimeADOQuery->ExecSQL();
}                       // Process
catch ( ... )           // Error adding
{
    Application->MessageBox("Error updating ProductionHours table!", "Table Error", MB_OK);
}                       // Error adding

This would be different if you were using parameters, a data set, or updating a record.



James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Does not work. Here are the errors that occur.

Code:
[BCC32 Error] Unit1.cpp(24): E2451 Undefined symbol 'MachineStr'
[BCC32 Error] Unit1.cpp(26): E2451 Undefined symbol 'MachineShiftStr'
[BCC32 Error] Unit1.cpp(27): E2451 Undefined symbol 'ProdHoursStr'
[BCC32 Error] Unit1.cpp(39): E2034 Cannot convert 'const char *' to 'const wchar_t *'
[BCC32 Error] Unit1.cpp(39): E2342 Type mismatch in parameter 'Text' (wanted 'const wchar_t *', got 'const char *')

You will be hard to attach a single project?
 
It's ok, I fixed the errors. But now it shows me the exact time and i don't need that. How can I fix that?
 
I'm not sure what you mean by "exact time."


James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
I wonder if "exact time" might mean a Time/Date stamp.

Do you NOT want a full time/date stamp? 2ffat's code should not include the time, but, if 2ffat's code does include the time, change the code to only provide the date.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top