Re: ODBC insert of SQL_TYPE_TIMESTAMP

Tech-Archive recommends: Fix windows errors by optimizing your registry



"LDJ" <LDJ@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:37FA6F9F-2352-4F86-B79C-6C262D8099A0@xxxxxxxxxxxxxxxx
Hi,
I'm trying to insert a time stamp into SQL Server (2005) and
can't figure
out the right combination of column type and arguments to
SQLBindParameter().

My C code currently looks like this:
rc = SQLBindParameter(hstmt, 7, SQL_PARAM_INPUT,
SQL_C_TYPE_TIMESTAMP, SQL_TYPE_TIMESTAMP, 10, 0,
(SQLPOINTER)&tstamp, 0, NULL);
I've tried different values for the ColumnSize and
DecimalDigits parameters,
including 10, 19, 22, 23, 26, and SQL_TIMESTAMP_LEN.

As for the table definition, I've tried DateTime, char(10),
char(19), etc.
Different combinations either give me return codes of 22008 or
42S02.

This is probably a little more than you want to see, but ...

We use our own DB objects to encapsulate ODBC access to Oracle,
DB2 and SQL Server (2000). Therefore, some extra code you won't
recognize. But, I think you're just looking for the Bind.
Please see below.
/////////////////////////////////////////////////////////////////////////////

//

void VParameter::PutDateTime( VDateTime dateTime )

{

SQLRETURN rc;

USHORT msec;

m_LenInd = sizeof( m_timeStamp );

dateTime.DecodeDate( m_timeStamp.year, m_timeStamp.month,
m_timeStamp.day );

dateTime.DecodeTime( m_timeStamp.hour, m_timeStamp.minute,
m_timeStamp.second, msec );

m_timeStamp.fraction = 0;

rc = SQLBindParameter( m_hStmt, m_paramNumber,

SQL_PARAM_INPUT, SQL_C_TYPE_TIMESTAMP, SQL_TIMESTAMP,

sizeof( "yyyy-mm-dd hh:mm:ss" ), 0,

&m_timeStamp, sizeof( m_timeStamp ), (SQLLEN *) &m_LenInd);

CHECK_STMT( m_hStmt, rc );

}



m_timeStamp is just the SQL timestamp struct. A VDateTime is our
own object, based on midnight Dec. 30, 1899 (that's a standard).
m_* are class variables.

Good luck,

- Arnie




.



Relevant Pages

  • Re: time stamp magicaly updated when ever update event occures on a row
    ... > in sql server 2000 i have a table. ... > field of the effected rows gets a new time stamp, ... > besides a table specific trigger that this time stamp could be getting ... It's part of the definition of column type timestamp, ...
    (microsoft.public.sqlserver.security)
  • Re: Code Page
    ... Try changing the column type to nvarcharand executing this query: ... when I enter them into the SQL Server (currently simply by setting ... >characters are all changed to meaningless characters, ... >strings so that the special characters don't get messed up when entered? ...
    (microsoft.public.inetserver.asp.db)
  • Re: Code Page
    ... Try changing the column type to nvarcharand executing this query: ... when I enter them into the SQL Server (currently simply by setting ... >characters are all changed to meaningless characters, ... >strings so that the special characters don't get messed up when entered? ...
    (microsoft.public.sqlserver.server)
  • Re: Code Page
    ... Try changing the column type to nvarcharand executing this query: ... when I enter them into the SQL Server (currently simply by setting ... >characters are all changed to meaningless characters, ... >strings so that the special characters don't get messed up when entered? ...
    (microsoft.public.sqlserver.programming)
  • Re: Code Page
    ... Try changing the column type to nvarcharand executing this query: ... when I enter them into the SQL Server (currently simply by setting ... >characters are all changed to meaningless characters, ... >strings so that the special characters don't get messed up when entered? ...
    (microsoft.public.sqlserver.clients)