Question

I have an application that run a lot of query using OleDbCommand. Every query is plain SQL text, and the command does not use parameters.

Now, the application should support chinese char and I do not wanto to change every query by adding the N char in front of the string to specify.

I am trying to do something like that, but It does not work:

        OleDbCommand command = new OleDbCommand("?", connect);
        command.CommandType = CommandType.Text;
        command.Parameters.AddWithValue("query", qry);
        OleDbDataAdapter da = new OleDbDataAdapter(command);

where qry is the query to execute without the N char in front of every string.

I really do not wat to change every query, it would be a mess.

Do you have a solution for me?

Was it helpful?

Solution

You will want to set the data type of the parameter, either using one of the Add overloads or creating a parameter using new, setting the property and then adding it to the collection.

Here are the OleDb datatypes:

http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbtype.aspx

VarWChar is unicode

If you are using SqlServer, then you might want to use the native driver so you can get the Sql data types, which have a more accurate matching.

If you are going for cross db compatiblity, then you might go in the opposite direction and use the System.Data.Common datatypes, DbType.XXX, ref http://msdn.microsoft.com/en-us/library/system.data.dbtype.aspx (or ODBC and it's type enumeration since MS said they are phasing out OleDb as a technology in favor of ODBC)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top