One of you here may be able to shed some light on this.

Running C# in VS2008/2010 and accessing VFP9 data using the VFP OLEDB and/or 
ODBC drivers. Everything works OK apart from passing parameters into a "SQL 
Select" statement i.e

//////////
// Start Code
String cConnection_String =
@"Dsn=Visual FoxPro 
Database;sourcedb=\\server\database.dbc;sourcetype=DBC;exclusive=No;backgroundfetch=Yes;collate=Machine;null=Yes;deleted=Yes";

OdbcConnection oConnection = new OdbcConnection();
oConnection.ConnectionString = cConnection_String;
oConnection.Open();
...
OdbcCommand cmd = new OdbcCommand();
cmd.Connection = oConnection;
...
// Get just date, zero time
String cDate_From = Convert.ToDateTime(DateTime.Today.ToShortDateString());
String cDate_From = dDate_From.ToString("dd/MM/yyyy");

cmd.CommandText = @"Select * from Header where  Header.Due_Date = @dStart_Date"
cmd.Parameters.AddWithValue("@dStart_Date", cDate_From)

DataTable oTable = new DataTable("curResult");
OdbcDataAdapter oAdapter = new OdbcAdapter(cmd);

int nRecords = oAdapter.Fill(oTable)
// End Code
/////////

The Fill() is where I get the error.

1. Passing in the date as a DateTime field I get:
ERROR [S1000] [Microsoft][ODBC Visual FoxPro Driver]Missing operand.

Thinking that I am passing in a DateTime field and comparing it to a VFP Date 
field lead me to changing the SQL "where" to read dtot(Header.Due_Date) but 
this gives the same error.

2. Passing in the date as a character string in the YYYYMMDD format and 
changinc the where clause to read "dtoc(Header.Date_Due,1) still gives the 
error in (1.) Just as a test to see if I could ever get it working I changed 
the @dStart_Date to be '@dStart_Date' and the query actually runs but doesn't

So, how can I pass a Date into an ODBC query and get it to work with Parameters 
and without manually constructing the SQL Statement as a character string? I 
know that constructing the SQL command manually works but I want to use 
parameters. I remember somewhere Rick posting about ODBC Parameters in that the 
Parameters are just taken in sequential order regardless of Name if using more 
than one of them and vaguely remember a potential problem about using functions 
in the ODBC but can't bring it to mind.

Oh, and exactly the same error is generated using OLEDB as opposed to ODBC.

Dave


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to