[Mono-dev] NullReference Exception for IDataReader.Get

Rafael Teixeira monoman at gmail.com
Sat Jul 21 09:38:25 EDT 2007


No, you should call the method that tells if the field is null (
IsDBNull() see http://msdn2.microsoft.com/en-us/library/system.data.idatarecord.isdbnull(VS.80).aspx),
and then call GetString() only if it returns false.

:)

On 7/19/07, ~ * ~ Srijith Unni ~ * ~ <srijith.unni at gmail.com> wrote:
> Hi All,
>
>          I am using Mono to read from a sqlite database, using IDataReader
>          I am getting a NullReference Exception when I have read a
> particular row and when i call reader.GetString method to retrieve a field.
> This happens only when the specific field in the row is empty. I was under
> the impression that if the field is empty , the method should return either
> null or an empty string. Don`t know why it is raising an Exception.
>
>     My code is like this,
>            IDbCommand cmd = Connection.CreateCommand ();
>             cmd.CommandText = query;
>
>             try {
>                 IDataReader reader = cmd.ExecuteReader ();
>                 while (reader.Read ()) {
>                        key = reader.GetString(offset + 1);
>                 ...
>                        }
>
> The stack trace seen is ,
>
>    Unhandled Exception: System.NullReferenceException: Object reference not
> set to an instance of an object
>             at Mono.Data.SqliteClient.SqliteDa
> taReader.GetString (Int32 i) [0x00000]
>
>
>    Am I doing something wrong or has this been rectified in a later version.
> I am using Mono 1.2.2 ( posting to this list, because it feels like a bug! )
>
>   Any help or comments, would be greatly appreciated.
>
> --
> Thanks & Regards,
> --
> A.Srijith.K.Unni
>
> Mail ID : srijith.unni at gmail.com
> Home Page : http://srijith.unni.googlepages.com/
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>


-- 
Rafael "Monoman" Teixeira
---------------------------------------
"I myself am made entirely of flaws, stitched together with good intentions."
Augusten Burroughs



More information about the Mono-devel-list mailing list