PC Review


Reply
Thread Tools Rate Thread

Access Query OleDbParameter problem

 
 
Steve
Guest
Posts: n/a
 
      2nd Nov 2005
I have an update routine that fills a OleDbCommand.Parameters collection
with 16 values. The last one is the criteria for the update. This worked
fine until I added the 14th and 15th parameters and now I get an exception:
"Data type mismatch in criteria expression."

There is no additional descriptions in the exception object. I have checked
the code, checked the order of parameters(Because Access seems to lame to
handle them in any other order than the order of the query) and I don't see
the problem.

Here is the Access Query Sql:

<code>
UPDATE Tbl_CustomerConfigs
SET Tbl_CustomerConfigs.ConfigName = [_configName],
Tbl_CustomerConfigs.Description = [_description],
Tbl_CustomerConfigs.IsDemo = [_isDemo],
Tbl_CustomerConfigs.BaseFrequency = [_baseFrequency],
Tbl_CustomerConfigs.QuartetLCDTopLine = [_quartetTopLine],
Tbl_CustomerConfigs.QuartetLCDBottomLine = [_quartetBottomLine],
Tbl_CustomerConfigs.DuetPlusLCDTopLine = [_duetPlusTopLine],
Tbl_CustomerConfigs.DuetPlusLCDBottomLine = [_duetPlusBottomLine],
Tbl_CustomerConfigs.DuetLCDTopLine = [_duetTopLine],
Tbl_CustomerConfigs.DuetLCDBottomLine = [_duetBottomLine],
Tbl_CustomerConfigs.LCDScrollSpeed = [_scrollSpeed],
Tbl_CustomerConfigs.LCDScrollInitHold = [_initHold],
Tbl_CustomerConfigs.LCDLoopCount = [_loopCount],
Tbl_CustomerConfigs.DateCreated = [_dateCreated],
Tbl_CustomerConfigs.DateModified = [_dateModified]
WHERE (((Tbl_CustomerConfigs.ConfigurationID)=[_configID]));
</code>


And here is my ADO DAL code:

<DAL code>
m_command.CommandText = GetAccessSprocString(m_spUpdateCustConfig);
m_command.Parameters.Clear();

OleDbParameter param = new OleDbParameter("_configName", config.Name);
m_command.Parameters.Add(param);

param = new OleDbParameter("_description", config.Description);
m_command.Parameters.Add(param);

param = new OleDbParameter("_isDemo", config.IsDemo);
m_command.Parameters.Add(param);

param = new OleDbParameter("_baseFrequency", config.BaseFrequency);
m_command.Parameters.Add(param);

param = new OleDbParameter("_quartetTopLine", config.QuartetLCDTopLine);
m_command.Parameters.Add(param);

param = new OleDbParameter("_quartetBottomLine",
config.QuartetLCDBottomLine);
m_command.Parameters.Add(param);

param = new OleDbParameter("_duetPlusTopLine", config.DuetPlusLCDTopLine);
m_command.Parameters.Add(param);

param = new OleDbParameter("_duetPlusBottomLine",
config.DuetPlusLCDBottomLine);
m_command.Parameters.Add(param);

param = new OleDbParameter("_duetTopLine", config.DuetLCDTopLine);
m_command.Parameters.Add(param);

param = new OleDbParameter("_duetPlusBottomLine", config.DuetLCDBottomLine);
m_command.Parameters.Add(param);

param = new OleDbParameter("_scrollSpeed", config.LCDScrollSpeed);
m_command.Parameters.Add(param);

param = new OleDbParameter("_initHold", config.LCDScrollInitHold);
m_command.Parameters.Add(param);

param = new OleDbParameter("_loopCount", config.LCDLoopCount);
m_command.Parameters.Add(param);

param = new OleDbParameter("_dateCreated", config.DateCreated);
m_command.Parameters.Add(param);

param = new OleDbParameter("_dateModified", config.DateModified);
m_command.Parameters.Add(param);

param = new OleDbParameter("_configID", config.ConfigID);
m_command.Parameters.Add(param);
</DAL code>



Does anyone see the problem? I sure don't. Hopefully someone can clue me
in.

Thanks for taking a look,
Steve


 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      3rd Nov 2005
Well, it looks like the 14th and 15th parameters are dates, yet you haven't
set them up as such. You should set the dataTpe property of the parameter
(actually, you should be doing this on all your parameters) and make sure
that the actual data being passed to that parameter matches the data type
specified.

BTW: Yes, you are right, an Access DB must have the parameters added to the
OleDBCommand's Parameters collection in the exact same sequence as they are
specified in the SQL statement.


"Steve" <(E-Mail Removed)> wrote in message
news:O8bdvQ$(E-Mail Removed)...
>I have an update routine that fills a OleDbCommand.Parameters collection
> with 16 values. The last one is the criteria for the update. This worked
> fine until I added the 14th and 15th parameters and now I get an
> exception:
> "Data type mismatch in criteria expression."
>
> There is no additional descriptions in the exception object. I have
> checked
> the code, checked the order of parameters(Because Access seems to lame to
> handle them in any other order than the order of the query) and I don't
> see
> the problem.
>
> Here is the Access Query Sql:
>
> <code>
> UPDATE Tbl_CustomerConfigs
> SET Tbl_CustomerConfigs.ConfigName = [_configName],
> Tbl_CustomerConfigs.Description = [_description],
> Tbl_CustomerConfigs.IsDemo = [_isDemo],
> Tbl_CustomerConfigs.BaseFrequency = [_baseFrequency],
> Tbl_CustomerConfigs.QuartetLCDTopLine = [_quartetTopLine],
> Tbl_CustomerConfigs.QuartetLCDBottomLine = [_quartetBottomLine],
> Tbl_CustomerConfigs.DuetPlusLCDTopLine = [_duetPlusTopLine],
> Tbl_CustomerConfigs.DuetPlusLCDBottomLine = [_duetPlusBottomLine],
> Tbl_CustomerConfigs.DuetLCDTopLine = [_duetTopLine],
> Tbl_CustomerConfigs.DuetLCDBottomLine = [_duetBottomLine],
> Tbl_CustomerConfigs.LCDScrollSpeed = [_scrollSpeed],
> Tbl_CustomerConfigs.LCDScrollInitHold = [_initHold],
> Tbl_CustomerConfigs.LCDLoopCount = [_loopCount],
> Tbl_CustomerConfigs.DateCreated = [_dateCreated],
> Tbl_CustomerConfigs.DateModified = [_dateModified]
> WHERE (((Tbl_CustomerConfigs.ConfigurationID)=[_configID]));
> </code>
>
>
> And here is my ADO DAL code:
>
> <DAL code>
> m_command.CommandText = GetAccessSprocString(m_spUpdateCustConfig);
> m_command.Parameters.Clear();
>
> OleDbParameter param = new OleDbParameter("_configName", config.Name);
> m_command.Parameters.Add(param);
>
> param = new OleDbParameter("_description", config.Description);
> m_command.Parameters.Add(param);
>
> param = new OleDbParameter("_isDemo", config.IsDemo);
> m_command.Parameters.Add(param);
>
> param = new OleDbParameter("_baseFrequency", config.BaseFrequency);
> m_command.Parameters.Add(param);
>
> param = new OleDbParameter("_quartetTopLine", config.QuartetLCDTopLine);
> m_command.Parameters.Add(param);
>
> param = new OleDbParameter("_quartetBottomLine",
> config.QuartetLCDBottomLine);
> m_command.Parameters.Add(param);
>
> param = new OleDbParameter("_duetPlusTopLine", config.DuetPlusLCDTopLine);
> m_command.Parameters.Add(param);
>
> param = new OleDbParameter("_duetPlusBottomLine",
> config.DuetPlusLCDBottomLine);
> m_command.Parameters.Add(param);
>
> param = new OleDbParameter("_duetTopLine", config.DuetLCDTopLine);
> m_command.Parameters.Add(param);
>
> param = new OleDbParameter("_duetPlusBottomLine",
> config.DuetLCDBottomLine);
> m_command.Parameters.Add(param);
>
> param = new OleDbParameter("_scrollSpeed", config.LCDScrollSpeed);
> m_command.Parameters.Add(param);
>
> param = new OleDbParameter("_initHold", config.LCDScrollInitHold);
> m_command.Parameters.Add(param);
>
> param = new OleDbParameter("_loopCount", config.LCDLoopCount);
> m_command.Parameters.Add(param);
>
> param = new OleDbParameter("_dateCreated", config.DateCreated);
> m_command.Parameters.Add(param);
>
> param = new OleDbParameter("_dateModified", config.DateModified);
> m_command.Parameters.Add(param);
>
> param = new OleDbParameter("_configID", config.ConfigID);
> m_command.Parameters.Add(param);
> </DAL code>
>
>
>
> Does anyone see the problem? I sure don't. Hopefully someone can clue me
> in.
>
> Thanks for taking a look,
> Steve
>
>



 
Reply With Quote
 
Steve
Guest
Posts: n/a
 
      4th Nov 2005
Hi Scott, thanks for the reply.
I sort of stumbled across the relaxed Parameter construction lacking type
specifier, size, etc. I kept using them because things seemed to magically
resolved to the correct type.
However, when I tried to set the DBType to a date type, I quickly found some
problems, namely WHICH date/time type was correct for .NET DateTime class
and then there is the question of the size parameter... I wasn't sure what
it was.

So in my messing around, I tried passing DateTime.ToString() instead of just
the DateTime and it solved the problem. It looks like passing just the
DateTime object would call ToString() with a formatter that would only send
the date. When I explicitly called ToString() it passed the full date and
time string.

You are right though, I should be specifying my types and sizes. I will be
jumping to SqlServer soon, so I will change that for my SQL DAL
implementation

Thanks again for the help,
Steve


"Scott M." <s-(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Well, it looks like the 14th and 15th parameters are dates, yet you

haven't
> set them up as such. You should set the dataTpe property of the parameter
> (actually, you should be doing this on all your parameters) and make sure
> that the actual data being passed to that parameter matches the data type
> specified.
>
> BTW: Yes, you are right, an Access DB must have the parameters added to

the
> OleDBCommand's Parameters collection in the exact same sequence as they

are
> specified in the SQL statement.
>
>
> "Steve" <(E-Mail Removed)> wrote in message
> news:O8bdvQ$(E-Mail Removed)...
> >I have an update routine that fills a OleDbCommand.Parameters collection
> > with 16 values. The last one is the criteria for the update. This

worked
> > fine until I added the 14th and 15th parameters and now I get an
> > exception:
> > "Data type mismatch in criteria expression."
> >
> > There is no additional descriptions in the exception object. I have
> > checked
> > the code, checked the order of parameters(Because Access seems to lame

to
> > handle them in any other order than the order of the query) and I don't
> > see
> > the problem.
> >
> > Here is the Access Query Sql:
> >
> > <code>
> > UPDATE Tbl_CustomerConfigs
> > SET Tbl_CustomerConfigs.ConfigName = [_configName],
> > Tbl_CustomerConfigs.Description = [_description],
> > Tbl_CustomerConfigs.IsDemo = [_isDemo],
> > Tbl_CustomerConfigs.BaseFrequency = [_baseFrequency],
> > Tbl_CustomerConfigs.QuartetLCDTopLine = [_quartetTopLine],
> > Tbl_CustomerConfigs.QuartetLCDBottomLine = [_quartetBottomLine],
> > Tbl_CustomerConfigs.DuetPlusLCDTopLine = [_duetPlusTopLine],
> > Tbl_CustomerConfigs.DuetPlusLCDBottomLine = [_duetPlusBottomLine],
> > Tbl_CustomerConfigs.DuetLCDTopLine = [_duetTopLine],
> > Tbl_CustomerConfigs.DuetLCDBottomLine = [_duetBottomLine],
> > Tbl_CustomerConfigs.LCDScrollSpeed = [_scrollSpeed],
> > Tbl_CustomerConfigs.LCDScrollInitHold = [_initHold],
> > Tbl_CustomerConfigs.LCDLoopCount = [_loopCount],
> > Tbl_CustomerConfigs.DateCreated = [_dateCreated],
> > Tbl_CustomerConfigs.DateModified = [_dateModified]
> > WHERE (((Tbl_CustomerConfigs.ConfigurationID)=[_configID]));
> > </code>
> >
> >
> > And here is my ADO DAL code:
> >
> > <DAL code>
> > m_command.CommandText = GetAccessSprocString(m_spUpdateCustConfig);
> > m_command.Parameters.Clear();
> >
> > OleDbParameter param = new OleDbParameter("_configName", config.Name);
> > m_command.Parameters.Add(param);
> >
> > param = new OleDbParameter("_description", config.Description);
> > m_command.Parameters.Add(param);
> >
> > param = new OleDbParameter("_isDemo", config.IsDemo);
> > m_command.Parameters.Add(param);
> >
> > param = new OleDbParameter("_baseFrequency", config.BaseFrequency);
> > m_command.Parameters.Add(param);
> >
> > param = new OleDbParameter("_quartetTopLine", config.QuartetLCDTopLine);
> > m_command.Parameters.Add(param);
> >
> > param = new OleDbParameter("_quartetBottomLine",
> > config.QuartetLCDBottomLine);
> > m_command.Parameters.Add(param);
> >
> > param = new OleDbParameter("_duetPlusTopLine",

config.DuetPlusLCDTopLine);
> > m_command.Parameters.Add(param);
> >
> > param = new OleDbParameter("_duetPlusBottomLine",
> > config.DuetPlusLCDBottomLine);
> > m_command.Parameters.Add(param);
> >
> > param = new OleDbParameter("_duetTopLine", config.DuetLCDTopLine);
> > m_command.Parameters.Add(param);
> >
> > param = new OleDbParameter("_duetPlusBottomLine",
> > config.DuetLCDBottomLine);
> > m_command.Parameters.Add(param);
> >
> > param = new OleDbParameter("_scrollSpeed", config.LCDScrollSpeed);
> > m_command.Parameters.Add(param);
> >
> > param = new OleDbParameter("_initHold", config.LCDScrollInitHold);
> > m_command.Parameters.Add(param);
> >
> > param = new OleDbParameter("_loopCount", config.LCDLoopCount);
> > m_command.Parameters.Add(param);
> >
> > param = new OleDbParameter("_dateCreated", config.DateCreated);
> > m_command.Parameters.Add(param);
> >
> > param = new OleDbParameter("_dateModified", config.DateModified);
> > m_command.Parameters.Add(param);
> >
> > param = new OleDbParameter("_configID", config.ConfigID);
> > m_command.Parameters.Add(param);
> > </DAL code>
> >
> >
> >
> > Does anyone see the problem? I sure don't. Hopefully someone can clue

me
> > in.
> >
> > Thanks for taking a look,
> > Steve
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vb.net 2008 - OleDbParameter Date problem Rob W Microsoft VB .NET 3 17th Jul 2009 09:13 PM
An OleDbParameter with ParameterName '@ID' is not contained by thisOleDbParameterCollection problem DC Microsoft ASP .NET 1 5th Oct 2006 04:11 PM
OleDbParameter.Direction giving problem =?Utf-8?B?dGJq?= Microsoft ADO .NET 1 26th Mar 2006 11:44 PM
problem with OleDbParameter =?Utf-8?B?VGF0dHlNYW5l?= bigpond.net.au> Microsoft Dot NET 6 7th Jan 2005 03:37 AM
OleDbParameter Query: Multiple parameters Steven K Microsoft ASP .NET 1 6th Mar 2004 05:33 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:45 PM.