Monday, March 12, 2012

Issue with SqlCeParameter (SqlCE 3.1)

Hi,

I have a simple query as follows:

SELECT COUNT(ID) FROM AI_DTREE DT WHERE PARENT =@.pPID AND

CARTRIDGE_ID = @.pCID AND COMMAND =@.pCMD AND OBJECT =@.pObj

Where @.pPID=16700130,@.pCID=43000000,@.pCMD=”=”, and

@.pObj=”the cecum, identified by appendiceal orifice & IC valve”

The filed OBJECT in AI_DTREE is of nvarchar(30)(of course the length of @.pObj is more than 30 in my current query).

I have build the SqlCeCommand sccmd object with the above sql text and the parameters.

returnval = sccmd.ExecuteScalar();

When I execute the above statement I am getting the following error:

ex.Message = "@.pObj : String truncation: max=30, len=55, value='the cecum, identified by appendiceal orifice & IC valve'."

But when I execute the same in Sql Server Management Studio against SqlCE db, it works fine and the result returnval =0.

How to overcome this SqlCeParameter issue?, for me it is difficult to messure the length of the filed before I exeuting the command.



Thanks


G Sreenaiah

You must ensure that the length of @.pObj is no more than 30 chars, or make the field bigger!|||

Hi Erik,
Thanks for your prompt reply.


I am just executing the above command from my C# code. If I want to ensure the length of the parameter is less than the length of field, then I should go for one more database hit to fetch field’s length first.


This is not the way happening with i) OleDbCommand, OleDbParameter, ii) OracleParameter, OracleCommand


Please let me know if anybody else has an idea how this can be resolved with workout having one more db hit to fetch fields’ length.


Why it is happening only with SqlCeCommand, SqlCeParameter? why not with OracleParameter, OracleCommand ?

Thanks
G Sreenaiah

No comments:

Post a Comment