[Mono-list] aspsqlprovider problem select table users

Francisco Figueiredo Jr. francisco at npgsql.org
Tue Mar 17 15:46:40 EDT 2009


2009/3/17 Rodrigo Cuevas <bellinux at gmail.com>:
> Hi Francisco, thank.
>

Hi, Rodrigo!
You are welcome!

> Other code with problem:
>
> MembershipUser user = Membership.GetUser("testuser"); //ok
> string pass = user.GetPassword(); //error
>
> Error:
>
> Unable to cast object of type 'System.DBNull' to type 'System.String'.
>
> D:\Sigem7\src\Npgsql2.0.4.src\src\Npgsql\NpgsqlDataReader.cs    Line: 306
> public override String GetString(Int32 i)
> Line 305:        {
> Line 306:            return (String) GetValue(i); //error
> Line 307:        }
>
> Stack Trace:
>
> [InvalidCastException: Unable to cast object of type 'System.DBNull' to type
> 'System.String'.]
>  Npgsql.NpgsqlDataReader.GetString(Int32 i) in
> D:\Sigem7\src\Npgsql2.0.4.src\src\Npgsql\NpgsqlDataReader.cs:306
>  NauckIT.PostgreSQLProvider.PgMembershipProvider.GetPassword(String
> username, String answer) in
> D:\Sigem7\src\NauckIT.PostgreSQLProvider-1.2.4.0\PgMembershipProvider.cs:782
>
> Error Npgsql 2.0.4 or  not ?
>

In this case, this error is by design.

Npgsql as well as other providers don't handle null values on their
get* methods.
You should call IsDBNull to test this.

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getint32.aspx

"No conversions are performed; therefore, the data retrieved must
already be a 32-bit signed integer.

Call IsDBNull to check for null values before calling this method."

I hope it helps.



-- 
Regards,

Francisco Figueiredo Jr.
Npgsql Lead Developer
http://www.npgsql.org
http://fxjr.blogspot.com
http://twitter.com/franciscojunior

Sent from: Brasilia DF Brazil.


More information about the Mono-list mailing list