gpt4 book ai didi

c# - 惊人的错误 "The given key was not present in the dictionary."

转载 作者:可可西里 更新时间:2023-11-01 08:17:40 25 4
gpt4 key购买 nike

我使用 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 + "=@param";
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;
};
}
}

异常:

The given key was not present in the dictionary.

线路:

drSQL = comSQL.ExecuteReader();

这很有趣,因为这个异常没有显示在消息框中!这就像一个运行时错误,而且我的 TRY 似乎根本不起作用!

最佳答案

using (MySqlConnection conSQL = new MySqlConnection(conSQLSTR))

在幕后,MySQL 将使用字典 将您的连接字符串解析为键/值对。确保您的连接字符串格式正确。

关于c# - 惊人的错误 "The given key was not present in the dictionary.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20162761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com