Re: DataReader Seek

From: Darren Shaffer (darrenshaffer_at_discussions.microsoft.com)
Date: 01/20/05


Date: Wed, 19 Jan 2005 21:08:41 -0700

Jeff,

I looked back through three or four code sections I have written using the Seek method on live projects
and syntax-wise you are right on the mark. The only thing I can think of that would produce a
null reference would be if there is not actually a value of 9 in the index you are using. It sounds
like there is though.

Assuming there is no sensitive data within, if you want to email me a copy of your .sdf, I'd be happy to
figure it out for you. I'm doing an MSDN webcast on 3/2 on SQL CE and would like to know if there is a
problem with CF sp3 and SQL CE 2.0, so I'd really like to look into this in detail.

ddshaff@nospam.hotmail.com

-- 
Darren Shaffer
Principal Architect
Connected Innovation
www.connectedinnovation.com
  "Jeff" <jeff@newsgroup.nospam> wrote in message news:eHaD4Gn$EHA.3236@TK2MSFTNGP15.phx.gbl...
  Thanks for the quick response Darren.  I gave it a try with your change and got the same result.  I tried compacting the database and renaming back to the original name and got the same result.  Any other ideas?
    "Darren Shaffer" <darrenshaffer@discussions.microsoft.com> wrote in message news:O7wEUMm$EHA.2552@TK2MSFTNGP09.phx.gbl...
    Jeff - your code looks correct to me, but give this a try:
    rdr.Seek(DbSeekOptions.FirstEqual, new object[]  {9} );
    Strictly speaking, the second param of the seek method requires an object, so either use
    the array notation above or do a new SqlInt32 and set it to a value of 9.
    Pls let me know how this works for you.
    -- Darren Shaffer
    "Jeff" <jeff@newsgroup.nospam> wrote in message news:%23ZuBWGl$EHA.2180@TK2MSFTNGP10.phx.gbl...
      I am getting a NullReferenceException when using the Seek function of the datareader and I cannot figure out why.  I have verified everything I can think of including Index name, etc.  I checked the database to make sure that a value of "9" was in the column that is indexed and it is.  All of this is in a try block - when it gets to rdr.Seek(DbSeekOptions.FirstEqual, 9) it throws the error.  I am running .netcf 1.0 sp3 in case that matters.  Here is my code:
      SqlCeConnection cn2 = new SqlCeConnection(@"Data Source=\Program Files\TestApp\Items.sdf");
      cn2.Open();
      //myItems is the table name
      SqlCeCommand cmdSelect2 = new SqlCeCommand("myItems",cn2);
      cmdSelect2.CommandType = CommandType.TableDirect;
      cmdSelect2.IndexName = "ItemIDNdx";
      SqlCeDataReader rdr = cmdSelect.ExecuteReader();
      // the next line throws a NullReferenceException
      rdr.Seek(DbSeekOptions.FirstEqual, 9);
      rdr.Read();
      myDesc = rdr["itemID"].ToString();
      This is driving me crazy - am i missing something?
      Thanks much.


Relevant Pages

  • Re: Setup up merge replication - problem with my config of MSSQLServer?
    ... Darren Shaffer wrote: ... > the SQL CE Server tools and SQL Server itself. ... > One obvious question - your machine that's running IIS and SQL ...
    (microsoft.public.sqlserver.ce)
  • Re: Sql Mobile Synchronization (reconcilor problem) !!!!
    ... > Microsoft SQL Server MVP / MCP ... >> Darren Shaffer ... >> .NET Compact Framework MVP ... >> Connected Innovation ...
    (microsoft.public.sqlserver.ce)
  • Re: select constant.field >> 10g float and double indicator
    ... > Mark C. Stock wrote: ... > I guess it uses some formatter which marks f as float. ... as BINARY_FLOAT and BINARY_DOUBLE data types in the 10g SQL Reference) ... instead of your original alias (of common usage but questionable etymology ...
    (comp.databases.oracle.misc)
  • Re: Slow GROUP BY
    ... I'm working on a quick recreation of your db in SQL Server CE so I can ... Suggest an index on the PunchItem table of ... Darren Shaffer ... > PunchList INNER JOIN Lot ON PunchList.LotId = Lot.Id INNER JOIN PunchItem ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: is this bad?
    ... >1) the ';' character must mark the end of a statement. ... >query sort by the first column then end the statement. ... You could remove all ';' marks from any SQL script and SQL ... Server will still happily execute it. ...
    (microsoft.public.sqlserver.programming)

Quantcast