Re: ODBC insert of SQL_TYPE_TIMESTAMP
- From: "Arnie" <99yoda@xxxxxxxxxxxxxxxx>
- Date: Wed, 16 Aug 2006 15:13:32 -0400
"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
.
- Follow-Ups:
- Re: ODBC insert of SQL_TYPE_TIMESTAMP
- From: Isa
- Re: ODBC insert of SQL_TYPE_TIMESTAMP
- Prev by Date: RE: [ODBC SQL Server Driver][TCP/IP Sockets]ConnectionWrite error
- Next by Date: Help with dtsrun and dts package.
- Previous by thread: Re: Connecting to SQL Server 7.0
- Next by thread: Re: ODBC insert of SQL_TYPE_TIMESTAMP
- Index(es):
Relevant Pages
|