我用SqlCe
作爲我的數據庫,但是當我複製所有表到MySql
數據庫這個異常開始!令人驚異的錯誤「給定的密鑰不在字典中。」
我的代碼:
using (MySqlConnection conSQL = new MySqlConnection(conSQLSTR))
{
try
{
conSQL.Open();
}
catch (MySqlException e)
{
string errMsg = e.Message;
MessageBox.Show(errMsg, "error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return false;
}
using (MySqlCommand comSQL = conSQL.CreateCommand())
{
comSQL.CommandText = "SELECT " + Column + " FROM " + TableName
+ " WHERE " + Column + "[email protected]";
comSQL.Parameters.Add("@param", MySqlDbType.VarChar);
comSQL.Parameters["@param"].Value = Value;
MySqlDataReader drSQL;
bool hasRows = false;
try
{
drSQL = comSQL.ExecuteReader();
hasRows = drSQL.Read();
}
catch (MySqlException e)
{
string errMsg =e.Message;
MessageBox.Show(errMsg, "error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
if (!hasRows)
return false;
else
{
return true;
};
}
}
例外:
給定的關鍵是不存在的字典。
線:
drSQL = comSQL.ExecuteReader();
因爲在消息框中沒有顯示這種異常有趣!它就像一個運行時錯誤,似乎我的TRY
根本不工作!
錯誤通常很驚人.. –
[橡皮鴨](http://en.wikipedia.org/wiki/Rubber_duck_debugging)更令人驚奇:) – Noctis
您的嘗試不起作用,因爲您正在抓住' MySqlException',而不是'Exception' – wudzik