PC Review


Reply
Thread Tools Rate Thread

DaraReader dosen't return row on the first call to Read

 
 
Jorgen D.
Guest
Posts: n/a
 
      12th Sep 2003
I'm using SqlCeDB and having troubels with prepared
commands and the data reader.

The first call to the Read method dosen't return a result,
but recreating the reader, and call the read method again
works as expected.

Here is a sample, which will display 2 messagboxes. The
first eith "Not Found" and the Second with "Found...".

What am I dooing wrong ?

Regards Joergen D.

SqlCeConnection cn = new SqlCeConnection(@"Data Source=\My
Documents\data.sdf");
cn.Open();

SqlCeCommand cmd = new SqlCeCommand("SELECT itemname from
Stocktable where itemnumber = ?",cn);

cmd.Parameters.Add("Ean",SqlDbType.NVarChar);
cmd.Prepare();
SqlCeDataReader dtr;

// 1st try
cmd.Parameters[0].Value="5703919000189";
dtr = cmd.ExecuteReader(CommandBehavior.SingleRow);
if (dtr.Read())
{
string s = dtr.GetString(0);
MessageBox.Show("1. try - Found: "+s);
}
else
{
MessageBox.Show("1. try - Not Found");
}
dtr.Close();

// 2nd try
cmd.Parameters[0].Value="5703919000189";
dtr = cmd.ExecuteReader(CommandBehavior.SingleRow);
if (dtr.Read())
{
string s = dtr.GetString(0);
MessageBox.Show("2. try - Found: "+s);
}
else
{
MessageBox.Show("2. try - Not Found");
}

dtr.Close();
cn.Close();
 
Reply With Quote
 
 
 
 
Ilya Tumanov [MS]
Guest
Posts: n/a
 
      18th Sep 2003
Jorgen,

I've tried this with Northwind database and it works as expected.
Is there something special about your database?

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>Content-Class: urn:content-classes:message
>From: "Jorgen D." <(E-Mail Removed)>
>Sender: "Jorgen D." <(E-Mail Removed)>
>Subject: DaraReader dosen't return row on the first call to Read
>Date: Fri, 12 Sep 2003 02:32:18 -0700
>Lines: 54
>Message-ID: <032d01c37910$c242ef30$(E-Mail Removed)>
>MIME-Version: 1.0
>Content-Type: text/plain;
> charset="iso-8859-1"
>Content-Transfer-Encoding: 7bit
>X-Newsreader: Microsoft CDO for Windows 2000
>X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
>Thread-Index: AcN5EMJADwABEVT4TLeCVWMVCmbZcQ==
>Newsgroups: microsoft.public.dotnet.framework.compactframework
>Path: cpmsftngxa06.phx.gbl
>Xref: cpmsftngxa06.phx.gbl

microsoft.public.dotnet.framework.compactframework:33422
>NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
>X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
>
>I'm using SqlCeDB and having troubels with prepared
>commands and the data reader.
>
>The first call to the Read method dosen't return a result,
>but recreating the reader, and call the read method again
>works as expected.
>
>Here is a sample, which will display 2 messagboxes. The
>first eith "Not Found" and the Second with "Found...".
>
>What am I dooing wrong ?
>
>Regards Joergen D.
>
>SqlCeConnection cn = new SqlCeConnection(@"Data Source=\My
>Documents\data.sdf");
>cn.Open();
>
>SqlCeCommand cmd = new SqlCeCommand("SELECT itemname from
>Stocktable where itemnumber = ?",cn);
>
>cmd.Parameters.Add("Ean",SqlDbType.NVarChar);
>cmd.Prepare();
>SqlCeDataReader dtr;
>
>// 1st try
>cmd.Parameters[0].Value="5703919000189";
>dtr = cmd.ExecuteReader(CommandBehavior.SingleRow);
>if (dtr.Read())
>{
> string s = dtr.GetString(0);
> MessageBox.Show("1. try - Found: "+s);
>}
>else
>{
> MessageBox.Show("1. try - Not Found");
>}
>dtr.Close();
>
>// 2nd try
>cmd.Parameters[0].Value="5703919000189";
>dtr = cmd.ExecuteReader(CommandBehavior.SingleRow);
>if (dtr.Read())
>{
> string s = dtr.GetString(0);
> MessageBox.Show("2. try - Found: "+s);
>}
>else
>{
> MessageBox.Show("2. try - Not Found");
>}
>
>dtr.Close();
>cn.Close();
>



 
Reply With Quote
 
Jorgen D.
Guest
Posts: n/a
 
      22nd Sep 2003
Hi Ilya.

Thanks for your reply.

I've also verified that it works as expected with the
Northwind DB, when searching on ProductID which is an
integer. But try search for a productname using
SqlCeCommand cmd = new SqlCeCommand("SELECT productid from
products where productname = ?",cn);
When searching on VarChar fields you will experience the
same "BUG"

Kind regards
Jorgen D.

>-----Original Message-----
>Jorgen,
>
>I've tried this with Northwind database and it works as

expected.
>Is there something special about your database?
>
>Best regards,
>
>Ilya
>
>This posting is provided "AS IS" with no warranties, and

confers no rights.
>
>--------------------
>>Content-Class: urn:content-classes:message
>>From: "Jorgen D." <(E-Mail Removed)>
>>Sender: "Jorgen D." <(E-Mail Removed)>
>>Subject: DaraReader dosen't return row on the first call

to Read
>>Date: Fri, 12 Sep 2003 02:32:18 -0700
>>Lines: 54
>>Message-ID: <032d01c37910$c242ef30$(E-Mail Removed)>
>>MIME-Version: 1.0
>>Content-Type: text/plain;
>> charset="iso-8859-1"
>>Content-Transfer-Encoding: 7bit
>>X-Newsreader: Microsoft CDO for Windows 2000
>>X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
>>Thread-Index: AcN5EMJADwABEVT4TLeCVWMVCmbZcQ==
>>Newsgroups:

microsoft.public.dotnet.framework.compactframework
>>Path: cpmsftngxa06.phx.gbl
>>Xref: cpmsftngxa06.phx.gbl

>microsoft.public.dotnet.framework.compactframework:33422
>>NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
>>X-Tomcat-NG:

microsoft.public.dotnet.framework.compactframework
>>
>>I'm using SqlCeDB and having troubels with prepared
>>commands and the data reader.
>>
>>The first call to the Read method dosen't return a

result,
>>but recreating the reader, and call the read method

again
>>works as expected.
>>
>>Here is a sample, which will display 2 messagboxes. The
>>first eith "Not Found" and the Second with "Found...".
>>
>>What am I dooing wrong ?
>>
>>Regards Joergen D.
>>
>>SqlCeConnection cn = new SqlCeConnection(@"Data

Source=\My
>>Documents\data.sdf");
>>cn.Open();
>>
>>SqlCeCommand cmd = new SqlCeCommand("SELECT itemname

from
>>Stocktable where itemnumber = ?",cn);
>>
>>cmd.Parameters.Add("Ean",SqlDbType.NVarChar);
>>cmd.Prepare();
>>SqlCeDataReader dtr;
>>
>>// 1st try
>>cmd.Parameters[0].Value="5703919000189";
>>dtr = cmd.ExecuteReader(CommandBehavior.SingleRow);
>>if (dtr.Read())
>>{
>> string s = dtr.GetString(0);
>> MessageBox.Show("1. try - Found: "+s);
>>}
>>else
>>{
>> MessageBox.Show("1. try - Not Found");
>>}
>>dtr.Close();
>>
>>// 2nd try
>>cmd.Parameters[0].Value="5703919000189";
>>dtr = cmd.ExecuteReader(CommandBehavior.SingleRow);
>>if (dtr.Read())
>>{
>> string s = dtr.GetString(0);
>> MessageBox.Show("2. try - Found: "+s);
>>}
>>else
>>{
>> MessageBox.Show("2. try - Not Found");
>>}
>>
>>dtr.Close();
>>cn.Close();
>>

>
>
>.
>

 
Reply With Quote
 
Ilya Tumanov [MS]
Guest
Posts: n/a
 
      22nd Sep 2003
Jorgen,

Yes, I can see it now. I'm not sure if it's a bug or not, however.
You see, you're calling cmd.Prepare() before command is actually ready:

cmd.Parameters.Add("Ean",SqlDbType.NVarChar);
cmd.Prepare(); << Command is not ready yet: parameter value is not set.
cmd.Parameters[0].Value="5703919000189"; << Now value is set, but command
is already prepared so new value has no effect.

To fix the problem, do not call cmd.Prepare() at all or move this call
after command is actually ready:

cmd.Parameters.Add("Ean",SqlDbType.NVarChar);
cmd.Parameters[0].Value="5703919000189";
cmd.Prepare();

Thanks for reporting this problem. I will investigate to determine if it's
a bug or a by design behavior.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>Content-Class: urn:content-classes:message
>From: "Jorgen D." <(E-Mail Removed)>
>Sender: "Jorgen D." <(E-Mail Removed)>
>References: <032d01c37910$c242ef30$(E-Mail Removed)>

<(E-Mail Removed)>
>Subject: RE: DataReader dosen't return row on the first call to Read
>Date: Mon, 22 Sep 2003 06:34:40 -0700
>Lines: 117
>Message-ID: <a88b01c3810e$462745d0$(E-Mail Removed)>
>MIME-Version: 1.0
>Content-Type: text/plain;
> charset="iso-8859-1"
>Content-Transfer-Encoding: 7bit
>X-Newsreader: Microsoft CDO for Windows 2000
>X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
>Thread-Index: AcOBDkYkfdJtKJpgSiG6hP2/q4Afdg==
>Newsgroups: microsoft.public.dotnet.framework.compactframework
>Path: cpmsftngxa06.phx.gbl
>Xref: cpmsftngxa06.phx.gbl

microsoft.public.dotnet.framework.compactframework:34090
>NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
>X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
>
>Hi Ilya.
>
>Thanks for your reply.
>
>I've also verified that it works as expected with the
>Northwind DB, when searching on ProductID which is an
>integer. But try search for a productname using
>SqlCeCommand cmd = new SqlCeCommand("SELECT productid from
>products where productname = ?",cn);
>When searching on VarChar fields you will experience the
>same "BUG"
>
>Kind regards
>Jorgen D.
>
>>-----Original Message-----
>>Jorgen,
>>
>>I've tried this with Northwind database and it works as

>expected.
>>Is there something special about your database?
>>
>>Best regards,
>>
>>Ilya
>>
>>This posting is provided "AS IS" with no warranties, and

>confers no rights.
>>
>>--------------------
>>>Content-Class: urn:content-classes:message
>>>From: "Jorgen D." <(E-Mail Removed)>
>>>Sender: "Jorgen D." <(E-Mail Removed)>
>>>Subject: DaraReader dosen't return row on the first call

>to Read
>>>Date: Fri, 12 Sep 2003 02:32:18 -0700
>>>Lines: 54
>>>Message-ID: <032d01c37910$c242ef30$(E-Mail Removed)>
>>>MIME-Version: 1.0
>>>Content-Type: text/plain;
>>> charset="iso-8859-1"
>>>Content-Transfer-Encoding: 7bit
>>>X-Newsreader: Microsoft CDO for Windows 2000
>>>X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
>>>Thread-Index: AcN5EMJADwABEVT4TLeCVWMVCmbZcQ==
>>>Newsgroups:

>microsoft.public.dotnet.framework.compactframework
>>>Path: cpmsftngxa06.phx.gbl
>>>Xref: cpmsftngxa06.phx.gbl

>>microsoft.public.dotnet.framework.compactframework:33422
>>>NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
>>>X-Tomcat-NG:

>microsoft.public.dotnet.framework.compactframework
>>>
>>>I'm using SqlCeDB and having troubels with prepared
>>>commands and the data reader.
>>>
>>>The first call to the Read method dosen't return a

>result,
>>>but recreating the reader, and call the read method

>again
>>>works as expected.
>>>
>>>Here is a sample, which will display 2 messagboxes. The
>>>first eith "Not Found" and the Second with "Found...".
>>>
>>>What am I dooing wrong ?
>>>
>>>Regards Joergen D.
>>>
>>>SqlCeConnection cn = new SqlCeConnection(@"Data

>Source=\My
>>>Documents\data.sdf");
>>>cn.Open();
>>>
>>>SqlCeCommand cmd = new SqlCeCommand("SELECT itemname

>from
>>>Stocktable where itemnumber = ?",cn);
>>>
>>>cmd.Parameters.Add("Ean",SqlDbType.NVarChar);
>>>cmd.Prepare();
>>>SqlCeDataReader dtr;
>>>
>>>// 1st try
>>>cmd.Parameters[0].Value="5703919000189";
>>>dtr = cmd.ExecuteReader(CommandBehavior.SingleRow);
>>>if (dtr.Read())
>>>{
>>> string s = dtr.GetString(0);
>>> MessageBox.Show("1. try - Found: "+s);
>>>}
>>>else
>>>{
>>> MessageBox.Show("1. try - Not Found");
>>>}
>>>dtr.Close();
>>>
>>>// 2nd try
>>>cmd.Parameters[0].Value="5703919000189";
>>>dtr = cmd.ExecuteReader(CommandBehavior.SingleRow);
>>>if (dtr.Read())
>>>{
>>> string s = dtr.GetString(0);
>>> MessageBox.Show("2. try - Found: "+s);
>>>}
>>>else
>>>{
>>> MessageBox.Show("2. try - Not Found");
>>>}
>>>
>>>dtr.Close();
>>>cn.Close();
>>>

>>
>>
>>.
>>

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MeasureString(string s,Font font) dosen't return right pixels =?Utf-8?B?a2VpdGg=?= Microsoft C# .NET 2 16th May 2006 04:18 PM
cd driver dosen't read audio cd's =?Utf-8?B?S2FyZW4=?= Windows XP General 2 1st Nov 2005 10:49 PM
Bitmap.GetPixel(x, y) dosen't return the right color Max Bolingbroke Microsoft Dot NET Compact Framework 7 22nd Mar 2005 05:14 PM
Why dosen't my taskbar return to normal when I reload Windows XP? =?Utf-8?B?ZmxldGNo?= Windows XP Help 1 7th Feb 2005 06:53 PM
RE: DataReader dosen't return row on the first call to Read Paul [Paradise Solutions] Microsoft Dot NET Compact Framework 1 10th Dec 2003 12:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:44 PM.