简体   繁体   English

给出“System.ArgumentException:'参数无效。' " 当我从数据库中检索图像时

[英]Gives "System.ArgumentException: 'Parameter is not valid.' " when i retrieving image from database

Help me retrieve an image from database to a PictureBox .帮助我从数据库检索图像到PictureBox

System.ArgumentException: '参数无效。

My code:我的代码:

conn.Open();

SqlCommand cmd = new SqlCommand("SELECT * FROM Members WHERE CardID = '" + textBox8.Text + "' OR EMP_ID = '" + textBox8.Text + "'", conn);

SqlDataAdapter daa = new SqlDataAdapter(cmd);

DataSet dss = new DataSet();
daa.Fill(dss);

if (dss.Tables[0].Rows.Count > 0)
{ 
        MemoryStream mss = new MemoryStream((byte[])dss.Tables[0].Rows[0]["Photo"]);

        pictureBox1.Image = new Bitmap(mss);
}

conn.Close();
 pictureBox1.Image = byteArrayToImage((byte[])dss.Tables[0].Rows[0]["Photo"]);

use below method:使用以下方法:

 public Image byteArrayToImage(byte[] byteArrayIn)
    {
        System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter();
        Image img = (Image)converter.ConvertFrom(byteArrayIn);

        return img;
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更新 Access 数据库后检索图像时出现问题(System.ArgumentException:'参数无效。') - Problem retrieving the image after updating the Access database (System.ArgumentException: 'Parameter is not valid.') System.ArgumentException:“参数无效。” 在 C# 中从 SQL Server 获取图像 - System.ArgumentException: 'Parameter is not valid.' in C# get image from SQL Server System.ArgumentException:参数无效。 GraphicsPath.AddString - System.ArgumentException: Parameter is not valid. GraphicsPath.AddString System.ArgumentException:参数无效。 在C#中 - System.ArgumentException: Parameter is not valid. in C# System.ArgumentException:'参数无效。 (showDialog错误) - System.ArgumentException: 'Parameter is not valid.' (showDialog error) Windows窗体:“ System.ArgumentException:参数无效。”来自系统堆栈 - Windows Forms: “System.ArgumentException: Parameter is not valid.” coming from System stack 参数无效-System.argumentException-图像处理 - Parameter not valid - System.argumentexception - Image Handling System.ArgumentException:“参数无效”内存流到图像 - System.ArgumentException: "Parameter is not Valid" Memorystream to Image System.ArgumentException:参数无效 - System.ArgumentException: Parameter is not valid C#System.ArgumentException:参数无效。 在System.Drawing.Bitmap..ctor(Stream stream) - C# System.ArgumentException: Parameter is not valid. at System.Drawing.Bitmap..ctor(Stream stream)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM