conversion problem
-
hi to all Function: --------- public static int GetScalar(string query) { OdbcConnection myconnGS = new OdbcConnection(); OdbcCommand mycmdGS = new OdbcCommand(); myconnGS = DBManager.getConnection(); mycmdGS = new OdbcCommand(query, myconnGS); return mycmdGS.ExecuteScalar();--error occured this line(patriculy mycmdGS) myconnGS.Close(); } error: Cannot implicitly convert type 'object' to 'int'. An explicit conversion exists (are you missing a cast?) D:\aesweb\WebSite\Controls\MainBannerAdControl.ascx.cs 98 16 D:\aesweb\WebSite\
Known Is Drop.Unknown Is Ocean
-
hi to all Function: --------- public static int GetScalar(string query) { OdbcConnection myconnGS = new OdbcConnection(); OdbcCommand mycmdGS = new OdbcCommand(); myconnGS = DBManager.getConnection(); mycmdGS = new OdbcCommand(query, myconnGS); return mycmdGS.ExecuteScalar();--error occured this line(patriculy mycmdGS) myconnGS.Close(); } error: Cannot implicitly convert type 'object' to 'int'. An explicit conversion exists (are you missing a cast?) D:\aesweb\WebSite\Controls\MainBannerAdControl.ascx.cs 98 16 D:\aesweb\WebSite\
Known Is Drop.Unknown Is Ocean
Well as the error message is saying, the result of an OdbcCommand.ExecuteScalar is an object. You have to cast this one to return an int. Have a look here: http://msdn.microsoft.com/en-us/library/system.data.odbc.odbccommand.executescalar.aspx And your myConnGS.Close() will never be executed. Try to improve your design here. Regards Sebastian.
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
hi to all Function: --------- public static int GetScalar(string query) { OdbcConnection myconnGS = new OdbcConnection(); OdbcCommand mycmdGS = new OdbcCommand(); myconnGS = DBManager.getConnection(); mycmdGS = new OdbcCommand(query, myconnGS); return mycmdGS.ExecuteScalar();--error occured this line(patriculy mycmdGS) myconnGS.Close(); } error: Cannot implicitly convert type 'object' to 'int'. An explicit conversion exists (are you missing a cast?) D:\aesweb\WebSite\Controls\MainBannerAdControl.ascx.cs 98 16 D:\aesweb\WebSite\
Known Is Drop.Unknown Is Ocean
write the following code instead of return mycmdGS.ExecuteScalar() return (int)mycmdGS.ExecuteScalar(); I hope it will work now Thank YOu Vinod Kr. Software Engineer EBC Publishing Lucknow