dimanche 1 novembre 2015

Input string was not in a correct format when convert string to double

I'm trying to do if else statement using c#. When I run the program, this error appear. It appears along the line "double x = Convert.ToDouble("XValue");". I was trying to convert the string X value to double to match with my variable x.

    static void Main(String[] args)
    {
        connectDB();
        OpenConnection();


        MySqlCommand command = c.CreateCommand();
        command.CommandText = "SELECT * FROM gazecoords INNER JOIN gazeperiod ON gazecoords.gazeID = gazeperiod.gazeID INNER JOIN trialImage on gazeperiod.imageID = trialImage.imageID INNER JOIN areacoords on trialImage.imageID = areacoords.trialImageID;";
        try
        {
            c.Open();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        MySqlDataReader reader = command.ExecuteReader();
        while (reader.Read())
        {
            Console.WriteLine(reader["imageID"].ToString());
            Console.WriteLine(reader["topLeftX"].ToString());
            Console.WriteLine(reader["topRightX"].ToString());
            Console.WriteLine(reader["topLeftY"].ToString());
            Console.WriteLine(reader["bottomLeftY"].ToString());
            Console.WriteLine(reader["XValue"].ToString());
            Console.WriteLine(reader["YValue"].ToString());
            Console.WriteLine(reader["in"].ToString());

            while (reader.Read())
            {

                double x = Convert.ToDouble("XValue");
                double y = Convert.ToDouble("YValue");
               List <int> image = new List<int>(Convert.ToInt32("imageID"));
               // int coordsID = Convert.ToInt32("coordsID");
                double topLeftX = Convert.ToDouble("topLeftX");
                double topRightX = Convert.ToDouble("topRightX");
                double topLeftY = Convert.ToDouble("topLeftY");
                double bottomLeftY = Convert.ToDouble("bottomLeftY");
                int inside = Convert.ToInt32("in");
                inside = 0;

                foreach (int coordsID in image)
                {
                    if (x > topLeftX && x < topRightX && y > topLeftY && y < bottomLeftY)
                    {
                        Console.WriteLine("The value inside are the area is {0}", inside + 1);
                    }
                    else
                        Console.WriteLine("0");
                    Console.ReadLine();
                }
            }
        }
    }

Aucun commentaire:

Enregistrer un commentaire