したがって、mysqlクエリを返す次の文字列がc#にあります。
string id = cmd.ExecuteScalar().ToString();
問題は、この文字列への入力が有効でない場合、アプリがクラッシュすることです。これによりアプリがクラッシュすることはありませんが、次のように表示されます。
MessageBox.Show("Your key (" + KeyNr + ") was invalid or not active. \nPlease check if it is the correct key or you need to buy another month.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
トライアンドキャッチで試してみましたが、うまくいきませんでした。誰かが助けることができますか?
私の試みのいくつか:
try
{
string id = cmd.ExecuteScalar().ToString();
}
catch (Exception ex)
{
MessageBox.Show("Your key (" + KeyNr + ") was invalid or not active. \nPlease check if it is the correct key or you need to buy another month.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
と
try
{
string id = cmd.ExecuteScalar().ToString();
}
catch (catch (MySqlException))
{
MessageBox.Show("Your key (" + KeyNr + ") was invalid or not active. \nPlease check if it is the correct key or you need to buy another month.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
すべてが私に与えます:
Error 2 The name 'id' does not exist in the current context