c# - c# - System.FormatException: 'Guid 应包含 32 位数字和 4 个破折号 (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)。'
问题描述
当我的数据库脱机时,我没有遇到此错误。我刚刚使用 db4free.net 使我的数据库联机。
每次我登录都会出现这个错误。有人可以指出什么问题吗?
private void btnLogIn_Click(object sender, EventArgs e)
{
string query = "select * from tbl_accounts where username='" + tbxUsername.Text + "' and password='" + tbxPassword.Text + "'";
MySqlCommand command = new MySqlCommand(query, connection);
MySqlDataAdapter da = new MySqlDataAdapter(command);
DataTable dt = new DataTable();
da.Fill(dt);
try
{
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
if (dt.Rows.Count > 0)
{
employee_id = (dr["employee_id"].ToString().PadLeft(4, '0'));
fullname = (dr["account_firstname"] + " " + dr["account_lastname"]).ToString();
this.Invoke(new Action(() =>
{
connection.Open();
command.ExecuteNonQuery();
connection.Close();
this.Close();
th = new Thread(openNewForm);
th.SetApartmentState(ApartmentState.STA);
th.Start();
}));
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
这是错误:
更新:这是我的连接字符串:
MySqlConnection connection = new MySqlConnection("datasource=db4free.net;Convert Zero Datetime=True;SslMode=none");
解决方案
距 OP 日期几乎整整 1 年,我在尝试使用 NuGet 包 MySQL.Data 时遇到了同样的错误
我在早期的 StackOverflow 帖子的评论中找到了解决方法
基本上,您可以通过添加OldGuids=True;
作为@noontz 提到的 MySQL DB 连接字符串的一部分来避免错误。
但是,正如@BradleyGrainger 所指出的,请注意,通过这样做,任何BINARY(16)
列都将返回为 aGuid
而不是byte[]
.
推荐阅读
- postgresql - 我应该回滚里面只有 COPY 的事务吗?
- python - 如何在 Tkinter 中同时调用多个按钮
- opengl - GL_ARB_uniform_buffer_object - 未定义 ARB 函数
- c# - 使用 c# 获取错误字符串未被识别为有效
- powershell - 标记“&&”在 laravel 版本 8 中不是有效的语句分隔符
- c - 在c中获取字符串数组的维度的问题
- c++ - cpp中关键字auto的两个实例
- python - Lambda 未解析的参考 python
- python - 将 CSV 文件作为列表导入会返回空列表
- powershell - 用于附加免责声明的 New-TransportRule