Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server CE / April 2008

Tip: Looking for answers? Try searching our database.

HELP: Baffled by bug (?) in SqlCeCommand:

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Matt - 28 Apr 2008 18:00 GMT
I am getting strange results running a SqlCeCommand (v3.1) in a .NET
application.

It is a select command, and the bug (?) depends on the first time the
command is used to retrieve results.  

If the table is entirely empty, then for the rest of the lifetime of the
SqlCeCommand, the WHERE clause is ignored.  Later retrievals using the
command return *all* rows in the table, despite a parameter that is
supposed to filter results to a single day.

If the table has even one row on the first invocation, the command works
correctly for the entire session.

The command is created only once upon app load and reused several times.

I assume this is a bug.  Maybe I just did something dumb.

Has anyone seen this before?  Any suggestions?

Matt

Code snippets:

Upon app load:

sSQL =
   "select entry_id, case len(entry_title) when 0 then '(no title)'
else   entry_title end as entry_title, priority "
   + "from ud_entry "
   + "where entry_date = @target_date "
   + "order by priority";
_sqlcmdGetDTitlesAndNewByTargetDate = new SqlCeCommand(sSQL, _sqlConn);
_sqlcmdGetDTitlesAndNewByTargetDate.Parameters.Add("@target_date",
SqlDbType.DateTime);

Upon selecting a new date:

       public DataTable GetDTitlesAndNewByDate(DateTime dateTarget)
       {
           _sqlcmdGetDTitlesAndNewByTargetDate.Parameters
["@target_date"].Value = dateTarget;

           DataTable dt = new DataTable();
           SqlCeDataAdapter da = new SqlCeDataAdapter
(_sqlcmdGetDTitlesAndNewByTargetDate);
           da.Fill(dt);

           DataRow dr = dt.NewRow();
           dr["entry_id"] = 0;
           dr["entry_title"] = "(new entry)";
           dr["priority"] = 0;

           dt.Rows.InsertAt(dr, 0);

           return dt;
       }
Ginny Caughey MVP - 28 Apr 2008 19:28 GMT
Matt,

Have you tried clearing the parmaters to the command, then adding back the
paramter for the new date?

Ginny

>I am getting strange results running a SqlCeCommand (v3.1) in a .NET
> application.
[quoted text clipped - 53 lines]
>            return dt;
>        }

Signature

Ginny Caughey
Device Application Development MVP

www.wasteworks.com
Software for Waste Management

Matt - 29 Apr 2008 16:32 GMT
> Matt,
>
> Have you tried clearing the parmaters to the command, then adding back
> the paramter for the new date?
>
> Ginny

Sounded promising, I tried it and it didn't fix.

What did work was toggling the connection for the cmd object:

   _sqlcmdGetDTitlesAndNewByTargetDate.Connection = null;
   _sqlcmdGetDTitlesAndNewByTargetDate.Connection = _sqlConn;

I've put this at the end of the save-new-entry routine and it fixes the
bug.  Ugly, but it works.

Thanks for the suggestion.  Set me on the right track and at least let me
know I wasn't missing something obvious (I'm new to SqlCE).

Matt

<snip me explaining the bizarre ignore-WHERE-clause scenario>
Ginny Caughey MVP - 29 Apr 2008 16:37 GMT
Thanks for reporting back, Matt.

Ginny

>> Matt,
>>
[quoted text clipped - 19 lines]
>
> <snip me explaining the bizarre ignore-WHERE-clause scenario>

Signature

Ginny Caughey
Device Application Development MVP

www.wasteworks.com
Software for Waste Management

Jin - 28 Apr 2008 23:50 GMT
> I am getting strange results running a SqlCeCommand (v3.1) in a .NET
> application.
[quoted text clipped - 53 lines]
>             return dt;
>         }

Two thoughts:

1.  Are you calling the Update() method for the DataAdapter at some
point?  I'm assuming that you are.
2.  DateTime has both Date and Time portions, so performing a query
with equal may not return the desired result unless you have exactly
the same value that includes the same Time component (including
seconds).  You may need to use/compare only the Date portion instead.

- Jin
Matt - 29 Apr 2008 16:38 GMT
Jin <jinsoochang@gmail.com> wrote in news:8c733a02-0d1c-49c4-8b6d-
e76ec25ef000@w7g2000hsa.googlegroups.com:

<snip explanation of sqlcecmd-ignores-WHERE-clause>

> Two thoughts:
>
[quoted text clipped - 6 lines]
>
> - Jin

No, all updates and inserts use separate command objects.  I have never
acquired the habit of using the recordset/adapter to run data
modifications.

Yeah, these should all be date-only datetimes.  Even if there was a time
component issue, I think that would cause me to lose expected records,
rather than ignore the filter and pull back the whole table.

Thanks for the reply.

Matt
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.