1 Replies - 625 Views - Last Post: 21 May 2012 - 02:18 PM Rate Topic: -----

#1 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 192
  • Joined: 25-April 11

Select Datetime from VFP-Database using OleDB

Posted 21 May 2012 - 05:33 AM

Hello Everybody

I am trying to get some data out of a FoxPro9-Database using the OleDB-Driver but it throws an error when using different types of dates. I'll show you an example:

I have the following function, which fills a DataGrid with the desired information:
public void SqlQuery(String SQL)
        {
            OleDbConnection conn = new OleDbConnection();
            conn.ConnectionString = "Provider=VFPOLEDB;" +
                                    "Data Source=dbfs\\drive.dbc;" +
                                    "Collating Sequence=machine;" +
                                    "Password=;" +
                                    "Mode=Share Deny Write;";
            conn.Open();

            OleDbCommand cmd = new OleDbCommand(SQL, conn);

            try
            {
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                DataTable DTable = new DataTable();
                da.Fill(DTable);


                dataGrid.DataSource = DTable;
                conn.Dispose();
                conn.Close();
            }
            catch (OleDbException e)
            {
                MessageBox.Show(e.ToString());
            }
        }


If I use this SQL-Command it works fine:
SqlQuery("SELECT * FROM hotges.dbf WHERE hot_erlsup = 'myname' AND hot_erldat >= DATE(2012,05,02) AND hot_erldat <= DATE(2012,05,03)");


But here I have a problem, because VFP-Databases use Datetime and not Date, so the command above would select only data starting from 02 May 2012 at 00:00:00 until 03 May 2012 at 00:00:00. I would like to select until 03 May 2012 at 23:59:59. If I use DATETIME() or SMALLDATETIME() or anything else it throws an error saying this function is missing...

How can I solve this problem?

Is This A Good Question/Topic? 0
  • +

Replies To: Select Datetime from VFP-Database using OleDB

#2 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 192
  • Joined: 25-April 11

Re: Select Datetime from VFP-Database using OleDB

Posted 21 May 2012 - 02:18 PM

OK... I have found a solution for my date problem. I can use VFP-Commands to get the date I want.

For example I can use CTOD() or better CTOT('myExpression') to parse my date. (CTOT means CharacterToTime)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1