-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Friday 04 Jul 2003 11:06 pm, Miguel de Icaza wrote:
> Lets examine the problem a bit more, because I was as perplexed as you
> were that a conversion from int to int would throw that exception.
>
> What is happening here is that "reader.GetOrdinal
> ("RealContentItemId")" returns an integer.
>
> And here is the problem: the returned int is used as the ColumnValue
> *key* whose value happens to be something different.
>
> Am not a System.Data expert, but this is either a bug on the original
> runtime, or there is a miss-conception in the
> System.Data.SqlClient.GetValue code.
>
> I added some extra information to the exception on CVS
>
> Miguel

Ok, I dropped in more test code again, like so:

Console.WriteLine ("Ord={0}, Value={1}", 
reader.GetOrdinal("RealContentItemId"), 
reader.GetOrdinal("RealContentItemId").GetType ());
Console.WriteLine ("Ord={0}, Value={1}", 
reader.GetOrdinal("OriginalVersionId"), 
reader.GetOrdinal("OriginalVersionId").GetType ());

Console.WriteLine ("Ord={0}, Value={1}", 
reader.GetOrdinal("RealContentItemId"), reader.GetDataTypeName 
(reader.GetOrdinal("RealContentItemId")));
Console.WriteLine ("Ord={0}, Value={1}", 
reader.GetOrdinal("OriginalVersionId"), reader.GetDataTypeName 
(reader.GetOrdinal("OriginalVersionId")));

which produced the following results:

Ord=2, Value=System.Int32
Ord=1, Value=System.Int32
Ord=2, Value=int
Ord=1, Value=int

So it appears as if what is coming back from GetOrdinal is a System.Int32, but 
GetDataTypeName seems to think of it as an Int. In any case, a conversion 
from System.Int32 or an Int to an Int should not cause any issues. So, a 
quick check of other things to go wrong has led to the actual culprit.

These lines of code fail:

if (reader.GetValue(reader.GetOrdinal("RealContentItemId")) == DBNull.Value)
        uniqueId = reader.GetInt32 (reader.GetOrdinal("OriginalVersionId"));
else
        uniqueId = reader.GetInt32 (reader.GetOrdinal("RealContentItemId"));

because the GetValue function is not actually returning a DBNull.Value and so 
the final line of code executes, which unfortunately contains a NULL in the 
database field. So, it would appear the code for GetValue on either 
IDataReader or SqlDataReader is faulty. Meanwhile, I better go put those 
reader.GetInt32 calls back in.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iQIVAwUBPwYQGPr1e7bH1pzBAQIHzBAAg6x2D6HACeengXqjF7tHIQwcGfMn3cBF
ekWkOxgJATX7gvmSvATyzHrgBKfRuitT6gGklZl05p9crpRXZyIXRUq+QhT2FCsO
STiQwyNnSnEKJcJ4rO76d89SefAwTI0rboYBh087Z0m1zjaPlwwnZgo5dVDC87gq
gli1GomdZifbxW/23OxUlW4NdpEKoOHJ6bDoHzA0xIHygeO56ZaEGphm6QEcx7o3
7bsWvgBjPRbmOyxzI9YK0iO1atog5fPKmWy46ppXC+0mehq8FiVG2k/ihlVskb2c
AXqs0qDw1gUpDPc4AejQ9jOfOV/ybajMISPZRZdLGf6+vnxOOO9teXb+9+NsI8mp
n9AdecXAV7RAeHGeO+sBJLmBytbc9qhbzxb9BeI0Gqu7Mgn6W58411uFSzKQc0J8
3lVauag0IO7HBTwWtuuZZ50BmwT40+OxCmuIPsuVhqIFlrTBV0VeVtqrmPXVk19H
X6q2xx4vcGrheSUVKJRa7In5K5mjhy++R0xvbeSW5asSgLxdZXqQbZCaXZqwlDag
UV/ccfK0QjOAGPMeXl8E3uiRe7yKW3zPysn3MXZCCi0nNcJnKFWc+pCk+rk4PCr0
4CD/QcqobaRCLhKlF9+0VzBL6vO7h+1KQpL/hzXHi1WAr8XWoGu2IPgrOekWjv8c
JD41dOG43mg=
=MiP5
-----END PGP SIGNATURE-----
_______________________________________________
Mono-list maillist  -  [EMAIL PROTECTED]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to