PRB: Updating a Table with DTOC() in an Index Using ODBC (259192)
The information in this article applies to:
- Microsoft ODBC Driver for Visual FoxPro (Build 6.00.8281.00) 6.0
This article was previously published under Q259192 SYMPTOMS
If you have a Visual FoxPro table containing an index with the DTOC() function in the index key expression and the index was built with CENTURY turned OFF and/or the DATE format was not AMERICAN, adding records or updating the table with the Visual FoxPro ODBC drivers may cause problems. If the index key expression is built using the DTOC() function and the ",1" parameter, your indexes work as expected.
CAUSE
The DTOC() function returns a character string corresponding to a Date or DateTime expression. The date format of this character string is determined by the SET CENTURY and SET DATE commands. The values placed into the index may vary depending on these environment settings at the time a record is added or updated. The default settings for the Visual FoxPro ODBC driver are DATE is AMERICAN and CENTURY is ON. If your application uses a different date format, it is not able to find those records using the index built with the DTOC() function.
RESOLUTION
Try one of the following to resolve this issue:
- Build your indexes with the DTOS() or DTOC(,1) functions.
- Make sure DATE is AMERICAN and CENTURY is ON when building and updating the index in Visual FoxPro.
- Re-index the table after updating through ODBC.
- Replace the DTOC() function call with the following expression (format may be changed to fit your needs: if your DATE is USA, use "-" instead of "/"):
For a 2 digit year:
PADL(MONTH(<date field>),2,"0") + "/" + PADL(DAY(<date field>),2,"0") + "/" + RIGHT(STR(YEAR(<date field>),4,0),2)
For a 4 digit year:
PADL(MONTH(<date field>),2,"0") + "/" + PADL(DAY(<date field>),2,"0") + "/" + STR(YEAR(<date field>),4,0)
- Change the DATE and CENTURY settings for the Visual FoxPro ODBC driver using SQL Passthrough commands (this code should be executed AFTER you open the remote view):
* to do this in Visual FoxPro
* get connection handle to table
lnHandle=CursorGetProp("ConnectHandle")
* if the DATE format was set to USA when the index was built
=SQLExec(lnHandle,"SET DATE USA")
* if CENTURY was OFF when the index was built
=SQLExec(lnHandle,"SET CENTURY OFF")
* perform table updates, index values will be created properly
STATUS
This behavior is by design.
REFERENCESFor additional information on the Visual FoxPro ODBC drivers and Dates, click the article numbers below
to view the articles in the Microsoft Knowledge Base:
229854 PRB: ODBC Query Fails with Non-American Date Format
176572 FIX: ODBC Date Filter Greater Than 12/31/1999 Return No Records
191926 FIX: VFP ODBC Driver Problem w/ {d 'yyyymmdd'} and Year > 1999
For additional information on indexing with Date/DateTime fields, click the article numbers below
to view the articles in the Microsoft Knowledge Base:
97066 HOWTO: Index a Combined Date and Character Field
253595 HOWTO: Build Indexes with DateTime Fields and Other Data Types
Modification Type: | Major | Last Reviewed: | 10/15/2002 |
---|
Keywords: | kbBug kbCodeSnippet kbDSupport kbprb KB259192 |
---|
|