acc
2018-08-16 19:23:02 UTC
int count;
using (OleDbCommand cmd = connection.CreateCommand()) {
cmd.CommandText = "SELECT COUNT(*) FROM MyTable";
//count = (int)cmd.ExecuteScalar(); // error (invalid cast)
count = (int)(decimal)cmd.ExecuteScalar(); // horror (but works)
}
using (OleDbCommand cmd = connection.CreateCommand()) {
cmd.CommandText = "SELECT COUNT(*) FROM MyTable";
object obj = cmd.ExecuteScalar();
Console.WriteLine("type: {0}", obj.GetType());
Console.WriteLine("value: '{0}'", obj.ToString());
}
Output:
type: System.Decimal
value: '9'
vfpoledb.dll version: 9.0.0.5815
Visual C# 2010 Express
Windows XP Pro SP3
System.Decimal? Why? Is this a bug?
using (OleDbCommand cmd = connection.CreateCommand()) {
cmd.CommandText = "SELECT COUNT(*) FROM MyTable";
//count = (int)cmd.ExecuteScalar(); // error (invalid cast)
count = (int)(decimal)cmd.ExecuteScalar(); // horror (but works)
}
using (OleDbCommand cmd = connection.CreateCommand()) {
cmd.CommandText = "SELECT COUNT(*) FROM MyTable";
object obj = cmd.ExecuteScalar();
Console.WriteLine("type: {0}", obj.GetType());
Console.WriteLine("value: '{0}'", obj.ToString());
}
Output:
type: System.Decimal
value: '9'
vfpoledb.dll version: 9.0.0.5815
Visual C# 2010 Express
Windows XP Pro SP3
System.Decimal? Why? Is this a bug?