HighTechTalks DotNet Forums  

My queries don't work after I upgraded to SQL Server Compact 3.5

Dotnet Framework (Compact Framework) microsoft.public.dotnet.framework.compactframework


Discuss My queries don't work after I upgraded to SQL Server Compact 3.5 in the Dotnet Framework (Compact Framework) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Star
 
Posts: n/a

Default My queries don't work after I upgraded to SQL Server Compact 3.5 - 01-01-2008 , 05:54 PM







Hi all,

I have upgraded my project to VS2008 and for some reason my queries
stopped working. I have spent almost the whole day trying different
things, but I always get a
'Cannot convert from Float to DateTime.' exception when the query
is executed.

This is my table:
http://luisespinosa.com/temp/table.jpg

and this is one of the queries that fail:

try
{
SqlCeParameter p3 = new SqlCeParameter("Latitude", SqlDbType.Float);
p3.Value = 3.2133;
SqlCeParameter p4 = new SqlCeParameter("Longitude", SqlDbType.Float);
p4.Value = 5.2133;
SqlCeParameter p5 = new SqlCeParameter("Speed", SqlDbType.Float);
p5.Value = 3.1;
SqlCeParameter p6 = new SqlCeParameter("Altitude", SqlDbType.Float);
p6.Value = 1.2;
SqlCeParameter p7 = new SqlCeParameter("DateAdded",
SqlDbType.DateTime);
p7.Value = DateTime.Now;
SqlCeParameter p8 = new SqlCeParameter("DateOccurred",
SqlDbType.DateTime);
p8.Value = DateTime.Now;

cSQL = "Insert into Positions
(Latitude,Longitude,Speed,Altitude,DateAdded,DateO ccurred) ";
cSQL += "VALUES (?,?,?,?,?,?)";

SqlCeCommand sqlCommand = m_DB.m_cConn.CreateCommand();

sqlCommand.CommandText = cSQL;
sqlCommand.Parameters.Add(p3);
sqlCommand.Parameters.Add(p4);
sqlCommand.Parameters.Add(p5);
sqlCommand.Parameters.Add(p6);
sqlCommand.Parameters.Add(p7);
sqlCommand.Parameters.Add(p8);


sqlCommand.ExecuteNonQuery();
}
catch (Exception e)
{
String eeee = e.Message;
}
Please... I hope somebody can help me with this. I don't know what else
to try.

Thanks

Reply With Quote
  #2  
Old   
Ginny Caughey [MVP]
 
Posts: n/a

Default Re: My queries don't work after I upgraded to SQL Server Compact 3.5 - 01-02-2008 , 04:59 PM






Star,

I was able to reproduce the error you saw even on the desktop. I was also
able to work around it (on desktop and CF) using this type of coding:

string cSQL = "Insert into Positions
(Latitude,Longitude,Speed,Altitude,DateAdded,DateO ccurred) ";
cSQL += "Values (@Latitude, @Longitude, @Speed, @Altitude, @DateAdded,
@DateOccurred) ";
SqlCeCommand sqlCommand = conn.CreateCommand();
sqlCommand.CommandText = cSQL;
sqlCommand.Parameters.AddWithValue("@Latitude", 3.2133);
sqlCommand.Parameters.AddWithValue("@Longitude", 5.2133);
sqlCommand.Parameters.AddWithValue("@Speed", 3.1);
sqlCommand.Parameters.AddWithValue("@Altitude", 1.2);
sqlCommand.Parameters.AddWithValue("@DateAdded", DateTime.Now);
sqlCommand.Parameters.AddWithValue("@DateOccurred" , DateTime.Now);
sqlCommand.ExecuteNonQuery();

I have seen something similar with SQL Server so I don't believe it's
specific to SQL Compact 3.5 or Compact Framework. In general I have fewer
problems using Parameters.AddWithValue, and it's a little less code.

HTH,

--
Ginny Caughey
Device Application Development MVP


"Star" <star (AT) nospam (DOT) com> wrote

Quote:
Hi all,

I have upgraded my project to VS2008 and for some reason my queries
stopped working. I have spent almost the whole day trying different
things, but I always get a
'Cannot convert from Float to DateTime.' exception when the query
is executed.

This is my table:
http://luisespinosa.com/temp/table.jpg

and this is one of the queries that fail:

try
{
SqlCeParameter p3 = new SqlCeParameter("Latitude", SqlDbType.Float);
p3.Value = 3.2133;
SqlCeParameter p4 = new SqlCeParameter("Longitude", SqlDbType.Float);
p4.Value = 5.2133;
SqlCeParameter p5 = new SqlCeParameter("Speed", SqlDbType.Float);
p5.Value = 3.1;
SqlCeParameter p6 = new SqlCeParameter("Altitude", SqlDbType.Float);
p6.Value = 1.2;
SqlCeParameter p7 = new SqlCeParameter("DateAdded",
SqlDbType.DateTime);
p7.Value = DateTime.Now;
SqlCeParameter p8 = new SqlCeParameter("DateOccurred",
SqlDbType.DateTime);
p8.Value = DateTime.Now;

cSQL = "Insert into Positions
(Latitude,Longitude,Speed,Altitude,DateAdded,DateO ccurred) ";
cSQL += "VALUES (?,?,?,?,?,?)";

SqlCeCommand sqlCommand = m_DB.m_cConn.CreateCommand();

sqlCommand.CommandText = cSQL;
sqlCommand.Parameters.Add(p3);
sqlCommand.Parameters.Add(p4);
sqlCommand.Parameters.Add(p5);
sqlCommand.Parameters.Add(p6);
sqlCommand.Parameters.Add(p7);
sqlCommand.Parameters.Add(p8);


sqlCommand.ExecuteNonQuery();
}
catch (Exception e)
{
String eeee = e.Message;
}
Please... I hope somebody can help me with this. I don't know what else to
try.

Thanks


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.