SQL CE and Parameter types

  • Thread starter Thread starter Gordon Scrim
  • Start date Start date
G

Gordon Scrim

Hi All,

I am having trouble getting the following to compile in C#. The
System.Data.SqlDbType is not recognised. I have looked in the help and it
would seem that it should be available and all the examples of using
parameterized queries against a SQL Server CE database use it but I cannot
get it to compile.

SqlCeCommand cmd = new SqlCeCommand();
cmd.Connection = ceCon;
cmd.CommandText = "INSERT INTO CLIENT (CLIE_ID) VALUES (?)";
cmd.Parameters.Add("@CLIE_ID", System.Data.SqlDbType.NVarChar, 10);

Any help much appreciated.


Gordon
 
Do you have a reference to System.Data.Common in your project? This is where
SqlDbType is defined.

Peter
 
Hi,

I tried that but it still does not compile. Says it is missing a reference
to a namespace. All the help points to SqlDbType being in System.Data not
in Common but I tried anyway.

I found that if I made a normal Windows app the following line is OK and
only needs System.Data to be used.

cmd.Parameters.Add("@CLIE_ID", SqlDbType.Int);

If I do the same in a ConmpactFramework app it does not compile.

I must be doing something silly but I can't figure it out.

regards

Gordon
 
Peter,

Thank you for your idea. When I re-read your message you said to add a
reference to System.Data.Common not put a using clause in which was what I
was doing. When I added the reference to it things finally compiled.

Can anyone tell me why this is the case that Common needs to be referenced
when the enumeration is called System.Data.SqlDbType? I thought I had my
head around namespaces pretty well but I obviously have not.

regards

Gordon
 
Back
Top