Bug #12837 documentation
Submitted: 26 Aug 2005 16:57 Modified: 17 Jul 2006 12:52
Reporter: Paul Evans Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Documentation Severity:S3 (Non-critical)
Version:1.0.4 OS:Windows (windows server 2000)
Assigned to: MC Brown CPU Architecture:Any

[26 Aug 2005 16:57] Paul Evans
Description:
c# example, within the documentation remarks of  "MySqlCommand.ExecuteScalar Method", doesn't work correctly in my envronment (ASP.NET 1.1)

The following line is the problem...

Int32 count = (int32) cmd.ExecuteScalar();

1. Typo: Int32 is correct. int32 is not. This line generates a compile time error. "The type or namespace name 'int32' could not be found"

2. With the typo corrected, it generates a run-time error "Specified cast is not valid."

How to repeat:
copy and past the documented line into your csharp script

Suggested fix:
To avoid the error, the following lines work for me...

object objCount = myCommand.ExecuteScalar();
Int32 count = Convert.ToInt32( objCount );

In summary the cast operator can't cope, but the Convert class can.

I guess this (untested) line should work...

Int32 count = Convert.ToInt32( myCommand.ExecuteScalar() );
[28 Aug 2005 6:02] Vasily Kishkin
Thanks for bug report. There is really typo in document (MySQLCommand.xml).
[17 Jul 2006 12:52] MC Brown
Fixed in the C/NET documentation.