我是一名使用c#的初學者。我試圖在c#
中使用if else語句進行編碼。當我運行該程序時,出現此錯誤消息。它沿着線double x = Convert.ToDouble("XValue");
出現。我試圖將字符串X值轉換爲double來匹配我的變量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();
}
}
}
}
唉呦。你沒有意識到你試圖解析'「XValue」'字符串,而不是'reader [「XValue」]'值? –
那麼'String''「XValue」'不代表任何'Double',對吧?然而,'reader [「XValue」]'可能包含一個'Double'值 –
XValue是如何存儲的? MySQL不具有「真正的」double類型,所以它必須存儲爲'string'?如果它必須是一個「字符串」,它將存儲什麼數字格式,以及哪種數字格式是您的默認值(CurrentCulture/CurrentUICulture)? – Corak