ADO.NET and the OleDbType

03/02/09

Permalink 07:34:58 pm, by truewill Email , 237 words, 181 views   English (US)
Categories: Tips, .NET, Windows, SQL, Persistence

ADO.NET and the OleDbType

I’m by no means an expert on ADO.NET. Most of the time I go through an O/RM (Gentle.NET) to handle persistent storage. (It’s a nice product, but it’s no longer being maintained.) A recent project needed to read an Access database, and we had built some SQL Server-specific layers on top of Gentle, so I dropped to ADO.NET and used OleDb to hit the Jet drivers.

Everything was working in my tests. When I tried it on a different machine, though, it failed with “Data type mismatch in criteria expression.” The Jet DLLs were the same. The base MDAC version was the same. The relevant schema in the database was the same.

I still don’t know what caused it, but I know how to fix it. I was using DbType to set the type of the SQL parameters. This was not mapping correctly to the OleDbType. For instance, DbType.String was mapping to OleDbType.VarWChar when the actual type was WChar (similarly with date types).

To fix it, I used View/Server Explorer in Visual Studio, connected to the database, then checked the column properties. I copied and pasted the OleDbType values into the code and set OleDbType directly for the parameters. Then I removed the connection in Server Explorer.

Note that this was all hand-coded C# - I was porting working code over from Delphi, and was not using any visual tools.

Comments, Pingbacks:

No Comments/Pingbacks for this post yet...

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.

Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email and url)
(Allow users to contact you through a message form (your email will NOT be displayed.))
The name truewill is composed of two other words. What is the SECOND word?

Development Central

Development Central is the blog of Bill Sorensen, a professional software developer. Much of this will relate to C#, .NET, and OOP in general.

Disclaimer
These postings are provided "AS IS" with no warranties and confer no rights.

Search

Categories

Linkblog

b2evolution

contributors

XML Feeds

What is RSS?

Who's Online?

  • Guest Users: 3

powered by b2evolution free blog software