Answer the question
In order to leave comments, you need to log in
How to fix a value not found exception in MySQL in C#?
There is this code:
string login = "serega404"; // если в базе нет этого ника то мы получаем исключение
string CommandText = "SELECT money FROM users WHERE login = '" + login + "'";
string Connect = "Database=bd;Data Source=localhost;User Id=root;Password=;SslMode=none";
MySqlConnection myConnection = new MySqlConnection(Connect);
MySqlCommand myCommand = new MySqlCommand(CommandText, myConnection);
myConnection.Open();
string money = myCommand.ExecuteScalar().ToString();
myConnection.Close();
return money;
Answer the question
In order to leave comments, you need to log in
Well, use try...catch...finally , something like this
try
{
string login = "serega404"; // если в базе нет этого ника то мы получаем исключение
string CommandText = "SELECT money FROM users WHERE login = '" + login + "'";
string Connect = "Database=bd;Data Source=localhost;User Id=root;Password=;SslMode=none";
MySqlConnection myConnection = new MySqlConnection(Connect);
MySqlCommand myCommand = new MySqlCommand(CommandText, myConnection);
myConnection.Open();
string money = myCommand.ExecuteScalar().ToString();
myConnection.Close();
return money;
}
catch (Exception ex)
{
Console.WriteLine("Ахтунг, нету такого: " + ex.Message);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question