Geeks With Blogs
Marcin Celej blog

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.

Posted on Sunday, October 1, 2006 5:45 PM | Back to top


Comments on this post: Adding SqlCeParameter programmatically requires @ with the parameter name

# re: Adding SqlCeParameter programmatically requires @ with the parameter name
Requesting Gravatar...
sqlcmd = new SqlCeCommand("INSERT INTO AddFile VALUES file = file2 ", connection);
sqlcmd.Parameters.Add(new SqlCeParameter("file2",SqlDbType.Image,bytBLOBData.Length)); //array of byte

sqlcmd.Parameters[0].Direction = ParameterDirection.Input;
sqlcmd.Parameters[0].Value = bytBLOBData;

sqlcmd.ExecuteNonQuery(); //here exception

Help me
Left by Blayej on Jul 27, 2011 7:41 PM

Your comment:
 (will show your gravatar)


Copyright © Marcin Celej | Powered by: GeeksWithBlogs.net