Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi every one still i have same problem please kindly help me to solve this problem..

Code:
double dResult = Convert.ToDouble(totalDep) - Convert.ToDouble(totalExp);

Hi every one in the above line of my code prompt me an error i.e
Input string was not in a correct format
and my query is getting System.Byte[] array please any one help me to solve this problem...!



Here is my Complete Code:

C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data;

public partial class Jqurey : System.Web.UI.Page
{
    DBconn db = new DBconn();
   // Security s = new Security();
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
           // user myUsers = new user();
            Response.Expires = -1;
            //required to keep the page from being cached on the client's browser

            Response.ContentType = "text/plain";
            string BankID = Request.QueryString["BankID"].ToString();

            string BankAmount = GetAmountInBank(BankID);
            Response.Write(BankAmount);

            Session["BankAmount"] = BankAmount;

        }

    }
    string GetAmountInBank(string Bank)
    {
        string strSQL = "select Sum(AmountinBank) from BankAccount,accountitem,accountcategory  where accountitem.ItemcatID=accountcategory.CategoryID  and BankAccount.ItemID=accountitem.ItemID   and accountcategory.IsExpense=1 and BankId '"+ Bank +"'" ;
        string totalExp = db.selectquery_One(strSQL).ToString();

        if (totalExp == "")
        {
            totalExp = "0";
        }


        strSQL = "select Sum(AmountinBank) from BankAccount,accountitem,accountcategory where accountitem.ItemcatID=accountcategory.CategoryID  and BankAccount.ItemID=accountitem.ItemID   and accountcategory.IsExpense=0 and BankId like '" + Bank + "'";

        string totalDep = db.selectquery_One(strSQL).ToString();

        if (totalDep == "")
        {
            totalDep = "0";
        }

        double dResult = Convert.ToDouble(totalDep) - Convert.ToDouble(totalExp);

        return dResult.ToString();
    }


}
Posted
Updated 6-Mar-13 18:36pm
v5
Comments
Jameel VM 5-Mar-13 2:10am    
Please share all the code you have tried
Naseer A Khan 5-Mar-13 2:47am    
sir I have posted my complete code..
Matej Hlatky 5-Mar-13 2:15am    
What query?
What types are totalDep and totalExp?
Naseer A Khan 5-Mar-13 3:42am    
in my code sir you can see totalDep and totalExp both are variable those data type is String
MalwareTrojan 5-Mar-13 2:31am    
What is the value for your variable during runtime?

Do not use Covert.ToDouble to convert double value. Always use Double.TryParse or Double.Parse to convert your value.

as explained by other, its your data which is not double type and hence you get this error. If you use TryParse it tells you string is not in the double format and wont throw exception.
 
Share this answer
 
Comments
Naseer A Khan 5-Mar-13 3:44am    
sir i have change Convert.ToDouble to Double.TryParse or Double.Parse but still having same issue
Jibesh 5-Mar-13 3:46am    
try to debug your application and see what's the value of 'totalDep' variable. it should be double type without any alphanumeric value.

debug and post the content of totalDep variable here
Naseer A Khan 5-Mar-13 3:58am    
sir i have debug point to point my code and in both variable totalDep and totalExp System.Byte[]
array shown.. and i have taken screen short during debug so is there any way to send you these screen shot...
Jibesh 5-Mar-13 4:01am    
You can upload your image in this link and past the link here. since you said the return value is Byte array can you debug the method db.selectquery_One returns the proper value as expected. we dont know whats inside this method.
Naseer A Khan 5-Mar-13 5:03am    
Sir here is my selectquery_One method:

public object selectquery_One(string query)
{
object obj="";

cammMYSQL = new MySqlCommand(query, connMYSQL);
try
{
if (connMYSQL.State == ConnectionState.Closed)
connMYSQL.Open();
obj=cammMYSQL.ExecuteScalar();

if (connMYSQL.State == ConnectionState.Open)
connMYSQL.Close();
if (obj == null) obj = "";
return obj;

}
catch (Exception e)
{
if (connMYSQL.State == ConnectionState.Open)

connMYSQL.Close();
return obj;
}

}
The error means that the string you're trying to parse a Double from doesn't actually contain a valid value.

use double.parse() or double.tryparse()

http://msdn.microsoft.com/en-us/library/system.convert.todouble.aspx[^]
 
Share this answer
 
v2
first check what is the returen type of
C#
db.selectquery_One(strSQL);
also try to put a brekpoint at

string totalExp = db.selectquery_One(strSQL).ToString();

and
string totalDep = db.selectquery_One(strSQL).ToString();


to see what value you are getting and as told by Jibesh use
C#
Double.TryParse 
or
C#
Double.Parse
to convert your value.
 
Share this answer
 
v2
Comments
Naseer A Khan 5-Mar-13 5:10am    
sir db.selecrtquery return my complete query in strSQl
CS2011 5-Mar-13 6:16am    
insted of this string totalExp = db.selectquery_One(strSQL).ToString();
try this

double totalExp = Convert.ToDouble(db.selectquery_One(strSQL));

see if this works
Naseer A Khan 5-Mar-13 6:32am    
sir i have made some changes as you mentioned but now its give me an error on next
line i.e
Error:
if (totalExp == "")
{
totalExp = "0";
}
Operator '==' cannot be applied to operands of type 'double' and 'string'
Cannot implicitly convert type 'string' to 'double'

Code:
string GetAmountInBank(string Bank)
{
string strSQL = "select Sum(AmountinBank) from BankAccount,accountitem,accountcategory where accountitem.ItemcatID=accountcategory.CategoryID and BankAccount.ItemID=accountitem.ItemID and accountcategory.IsExpense=1 and BankId like '" + Bank + "'";
double totalExp = Convert .ToDouble ( db.selectquery_One(strSQL));

if (totalExp == "")
{
totalExp = "0";
}
CS2011 5-Mar-13 6:47am    
Just remove the if condition from both places and when i say remove if it means delete the code below
if (totalExp == "")
{
totalExp = "0";
}
Naseer A Khan 5-Mar-13 6:58am    
sir i have removed this condition from both places and Run my Project now i have this Error

ERROR: Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.
i think before conversion u should check variables(totalDep,totalExp) have values or not .
can u show your code
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900