Crash while select query via OleDB with parameters to Access DB
- From: stalkeridze@xxxxxxx
- Date: 21 Apr 2006 09:07:12 -0700
Hi all.
I have a problem with using of OleDB query with parameters.
There is an application with two working databases - MS SQL and Access
We change all queries to DB by using parameters instead of creating
query by code.
The application work correctly with MS SQL, but often throws an
exception "Data type mismatch in criteria expression."
The query is
Select TOP 5 ROOTNODENAME AS DESCRIPTION, COUNT(*) AS REPORTCOUNTER,
SUM(EVENTCOUNT) AS EVENTCOUNT1, SUM(SUMDURATION) / SUM(EVENTCOUNT) /
1000 AS AVERAGEDURATION, MAX(MAXID) AS MAXEVENTID
SELECT B.ROOTNODENAME, B.USERNAME, COUNT(*) AS EVENTCOUNT,From (
SUM(EVENTDURATION) AS SUMDURATION, MAX(EVENTID) AS MAXID
FROM V_EVENT B
WHERE EVENTCLASSTYPE='performance' AND UTCEVENTDATE>=? AND
UTCEVENTDATE<=? AND
(( SOURCE IN (
SELECT SRC.SOURCE
FROM APPLICATIONSOURCE APP1, APPLICATION APP2, SOURCE SRC
WHERE SRC.SOURCEID=APP1.SOURCEID AND APP1.APPLICATIONID =
APP2.APPLICATIONID
AND (APP2.APPLICATION IN (?,?)))))
and ((SOURCE IN (?,?)))
GROUP BY ROOTNODENAME, USERNAME)
A
Group By ROOTNODENAME Order By 2 DESC
i.e. contains 6 parameters - 2 as data and 4 as string
the code is
String connectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test3.mdb";
OleDbConnection myConnection = new OleDbConnection(
connectionString );
OleDbCommand myCommand = new OleDbCommand( select,
myConnection );
OleDbParameter[] myParameter = new OleDbParameter[6];
OleDbDataAdapter da = new OleDbDataAdapter( myCommand );
DataSet ds = new DataSet();
myParameter[0] = new OleDbParameter( "@d1", new DateTime(
2006, 2, 1 ));
myParameter[0].OleDbType = OleDbType.Date;
myParameter[1] = new OleDbParameter( "@d2", DateTime.Now );
myParameter[1].OleDbType = OleDbType.Date;
myParameter[2] = new OleDbParameter( "@A1", "ALL" );
myParameter[2].OleDbType = OleDbType.VarChar;
myParameter[3] = new OleDbParameter( "@A2", "TEST" );
myParameter[3].OleDbType = OleDbType.VarChar;
myParameter[4] = new OleDbParameter( "@S1", "BlaBla" );
myParameter[4].OleDbType = OleDbType.VarChar;
myParameter[5] = new OleDbParameter( "@S2", "BlaBlaBla" );
myParameter[5].OleDbType = OleDbType.VarChar;
for( int index=0; index<100; index++ )
{
if( myParameter[index] != null )
myCommand.Parameters.Add( myParameter[index] );
}
myConnection.Open();
da.Fill( ds );
dgTest.DataSource = ds.Tables[0];
If I remove the Data parameters - all is worked OK.
If I remove the first two String parameters - all is worked OK too.
But it doesn't work together :(
Is somebody occures this trouble?
I will be happy to see any decision of this one...
Thanks
.
- Prev by Date: C# code to convert HTML file into RTF file format
- Next by Date: Re: Can't connect to SQL server
- Previous by thread: C# code to convert HTML file into RTF file format
- Next by thread: Re: Exclusive connection to Access Database
- Index(es):
Relevant Pages
|
Loading