system.invalidoperationException:'连接必须有效并打开。'
我正在使用.NET和MySQL数据库在C#中开发一个程序。 一旦登录用户,我就需要可见用户图像,为此,我有一个称为“ image”的Longblob类型列。登录过程很好,但是发生以下错误,
Connection must be valid and open.
我正在使用以下代码从数据库中进行选择:
MySqlCommand command1 = new MySqlCommand("select `user Image` from `userdb` where `username` = @img", con);
command1.Parameters.Add("@img", MySqlDbType.Blob);
command1.Parameters["@img"].Value = Admin;
byte[] img = (byte[])command1.ExecuteScalar();
if (img == null)
{
pic_profilePic.Image = null;
}
else
{
var DATA = (byte[])command1.ExecuteScalar();
var stream = new MemoryStream(DATA);
pic_profilePic.Image = Image.FromStream(stream);
}
尽管将列类型更改为二进制和Varbinary,但我仍然遇到相同的错误。
有人知道我在这里做错了吗?
I am developing a program in C # with .NET and MySQL databases.
I need the user image to be visible once the user is logged in, for which I have a LONGBLOB type column called 'Image'. The login process was good, but the following error occurred
Connection must be valid and open.
I'm using the following code to select from the database:
MySqlCommand command1 = new MySqlCommand("select `user Image` from `userdb` where `username` = @img", con);
command1.Parameters.Add("@img", MySqlDbType.Blob);
command1.Parameters["@img"].Value = Admin;
byte[] img = (byte[])command1.ExecuteScalar();
if (img == null)
{
pic_profilePic.Image = null;
}
else
{
var DATA = (byte[])command1.ExecuteScalar();
var stream = new MemoryStream(DATA);
pic_profilePic.Image = Image.FromStream(stream);
}
Despite changing the column type into binary and varbinary, I still got the same error.
Does anyone know what I'm doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请检查您的代码以打开您的
连接
Please check your code to open your connection
Also remember to close it after you are done