posts - 50, comments - 126, trackbacks - 6

My Links

News



View Marcin Celej's profile on LinkedIn

Archives

Post Categories

Adding SqlCeParameter programmatically requires @ with the parameter name

I am developing Pocket PC application at the moment and I use SQL Server 2005 Everywhere inside. I encountered some difference to other ADO.NET providers. The difference is in adding SqlCeParameter programmatically to a SqlCeCommand. Here is the code I had:

SqlCeCommand select = new SqlCeCommand("select Version from Customer where ID = @id", connection);
select.Parameters.Add("id", System.Data.SqlDbType.BigInt).Value = id;
object result = select.ExecuteScalar();

You can see that in the query there is a parameter @id, but in the second line (where I create the parameter and set its value) there is no @ in the parameter name. Such code does not work. It throws exception: 'An SqlCeParameter with ParameterName '@id' is not contained by this SqlCeParameterCollection.'.

To make it working you need to provide parameter name with @ at the beginning.
As far as I am concerned the @ sign is not required with parameter name in standard SQL ADO.NET provider.

Print | posted on Sunday, October 01, 2006 5:45 PM |

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: