c# - 检索图像时出现“参数无效”错误
问题描述
我想使用 C# 从 SQL Server 数据库中检索图像。但是,我收到错误消息
参数无效
请帮我。
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string q = "select * from Rough where name='" + comboBox1.Text + "'";
SqlConnection con = new SqlConnection("Data Source=(local);Initial Catalog=SMS_DB;Integrated Security=True");
SqlCommand cmd = new SqlCommand(q, con);
SqlDataReader dr;
if (con.State == ConnectionState.Closed)
{
con.Open();
dr = cmd.ExecuteReader();
byte[] img = null;
while (dr.Read())
{
textBox1.Text = (dr["ID"].ToString());
textBox2.Text = (dr["Name"].ToString());
textBox3.Text = (dr["Image"].ToString());
img = (byte[])(dr["Image"]);
if (img == null)
{
pictureBox2.Image = null;
}
else
{
MemoryStream ms = new MemoryStream(img);
pictureBox2.Image = Image.FromStream(ms);
// ms.Close();
}
}
con.Close();
}
}
解决方案
推荐阅读
- regex - 将字符串匹配为文本的正则表达式
- django - 在 Django 中定义下拉框的最简单方法是什么?
- c# - 如果这个值等于这个 json 的另一个值,则在几个 json 字段中检索一个值
- node.js - Axios GET 请求将空的 req.body 发送到服务器
- mysql - MySql 按最新日期选择用户
- c# - 如何在主视图模型和用户控制视图模型之间进行通信
- ubuntu - 转换为 PKCS12
- javascript - copyFileSync 与 writeFileSync
- python - 如何在机器学习中获得预测概率
- vue.js - Vuelidate 检查数组有模糊的项目