My Client is getting the following error randomly. I even not able to find out the reason.
Error:
Exception type : InvalidCastException
Exception message: Unable to cast object of type 'System.Boolean' to type 'System.String'.
Stack Trace:
Stack trace: at BindTypes.GetAgreement(String userA)
at billenroll_Wizard.Page_Load(Object sender, EventArgs e)
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
According to my understanding based on stack trace, this error occurs on the following function.
public class BindTypes
{
public static string GetAgreement(string A)
{
string tab = "";
if (A == "biller")
{
tab = "b_agreement";
}
else
{
tab = "r_agreement";
}
db = new DBdefault();
string sql = "SELECT ["+tab+"] FROM [messages] WHERE [id] = '0'";
return (string)db.GetScalar(sql);
}
}
I don't know where it is going wrong. My Query will return string values like this 'I am here'. Hence I am returning the same string. In that function i am NOT doing any work with Boolean.
The actual value, the query returns is "According to agreement...' like that it will go on..
you have to check your above method db.GetScalar(sql). and also try to figure out in what case your application is throwing error. you have to check with those record on which you are getting error.
If this post answered your question or solved your problem, please Mark it as Answer.
That table is having only one record. By based on user we will show the values of different column. And I don't know in what case it is throwing the error. If i know i would have fixed that.
joshuait
Member
65 Points
114 Posts
Unable to cast object of type 'System.Boolean' to type 'System.String'
Sep 07, 2012 07:06 AM|LINK
Hi all,
My Client is getting the following error randomly. I even not able to find out the reason.
Error:
Stack Trace:
According to my understanding based on stack trace, this error occurs on the following function.
public class BindTypes { public static string GetAgreement(string A) { string tab = ""; if (A == "biller") { tab = "b_agreement"; } else { tab = "r_agreement"; } db = new DBdefault(); string sql = "SELECT ["+tab+"] FROM [messages] WHERE [id] = '0'"; return (string)db.GetScalar(sql); } }Joshua
Ramesh Chand...
Star
12922 Points
2672 Posts
Re: Unable to cast object of type 'System.Boolean' to type 'System.String'
Sep 07, 2012 07:12 AM|LINK
you.
joshuait
Member
65 Points
114 Posts
Re: Unable to cast object of type 'System.Boolean' to type 'System.String'
Sep 07, 2012 07:20 AM|LINK
Hi Ramesh,
I need to return string value and my query will return string value. Here there is no way for Boolean values.
Joshua
oned_gk
All-Star
31473 Points
6427 Posts
Re: Unable to cast object of type 'System.Boolean' to type 'System.String'
Sep 07, 2012 07:49 AM|LINK
if (db.GetScalar(sql)) { return "True" else Return "False" }Ramesh Chand...
Star
12922 Points
2672 Posts
Re: Unable to cast object of type 'System.Boolean' to type 'System.String'
Sep 07, 2012 08:23 AM|LINK
Sorry, it was my mistake, you have to do like this.
or
joshuait
Member
65 Points
114 Posts
Re: Unable to cast object of type 'System.Boolean' to type 'System.String'
Sep 07, 2012 08:29 AM|LINK
Hi Ramesh,
I don't know where it is going wrong. My Query will return string values like this 'I am here'. Hence I am returning the same string. In that function i am NOT doing any work with Boolean.
The actual value, the query returns is "According to agreement...' like that it will go on..
Joshua
Ramesh Chand...
Star
12922 Points
2672 Posts
Re: Unable to cast object of type 'System.Boolean' to type 'System.String'
Sep 07, 2012 08:36 AM|LINK
you have to check your above method db.GetScalar(sql). and also try to figure out in what case your application is throwing error. you have to check with those record on which you are getting error.
oned_gk
All-Star
31473 Points
6427 Posts
Re: Unable to cast object of type 'System.Boolean' to type 'System.String'
Sep 07, 2012 08:37 AM|LINK
BEGIN IF EXISTS (SELECT * FROM .....) RETURN 'Hello' ELSE RETURN 'xxx' ENDoned_gk
All-Star
31473 Points
6427 Posts
Re: Unable to cast object of type 'System.Boolean' to type 'System.String'
Sep 07, 2012 08:37 AM|LINK
BEGIN IF EXISTS (SELECT * FROM .....) RETURN 'Hello' ELSE RETURN 'xxx' ENDjoshuait
Member
65 Points
114 Posts
Re: Unable to cast object of type 'System.Boolean' to type 'System.String'
Sep 07, 2012 08:40 AM|LINK
Hi Ramesh,
That table is having only one record. By based on user we will show the values of different column. And I don't know in what case it is throwing the error. If i know i would have fixed that.
Joshua