Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用sqldatareader在c#中的Datagrid的pictureBox中显示图像_C# - Fatal编程技术网

使用sqldatareader在c#中的Datagrid的pictureBox中显示图像

使用sqldatareader在c#中的Datagrid的pictureBox中显示图像,c#,C#,我在Datagrid的pictureBox中显示图像时遇到问题。我使用sqlconnection并使用sqldatareader获取数据。我在sql server中以systembyte格式保存了图片,但单击datagrid中的行时无法显示图片 请帮助我 将值从读取器加载到DATAGRID oCon.Open(); SqlCommand get_company_histroy = new SqlCommand("sp_select_company_history", oCon); get_

我在Datagrid的pictureBox中显示图像时遇到问题。我使用sqlconnection并使用sqldatareader获取数据。我在sql server中以systembyte格式保存了图片,但单击datagrid中的行时无法显示图片

请帮助我

将值从读取器加载到DATAGRID

 oCon.Open();
 SqlCommand get_company_histroy = new SqlCommand("sp_select_company_history", oCon);
 get_company_histroy.CommandType = CommandType.StoredProcedure;
 get_company_histroy.Parameters.Add("@Company_Code ",txtdetailcompcode.Text);

 oDr = get_company_histroy.ExecuteReader();

 ArrayList sequence = new ArrayList();
 while (oDr.Read())
 {
     Get_Histroy His = new Get_Histroy();
     His.Photo = oDr[6].ToString();
     sequence.Add(His);

     //txtcompdetailhisfounder.Text = Convert.ToString(oDr["History_Founder"]);
     //DTP_comp_details_his_since.Text=Convert.ToString (oDr["History_Since"]);
 }
 DG_Mas_Com_History.DataSource = sequence;
用于从读取器获取值的类

public class Get_Histroy
{
    public  string Photo
    {
        get { return History_Photo; }
        set { History_Photo=value; }
    }
}
DATAGRID单击事件

private void DG_Mas_Com_History_CellClick(object sender, DataGridViewCellEventArgs e)
{
    try
    {
        if (e.RowIndex >= 0)
            get_company_histroy.Parameters.Add("@Company_Code ", txtdetailcompcode.Text);
        oDr = get_company_histroy.ExecuteReader();

        byte[] picarr = (byte[])DG_Mas_Com_History.Rows[e.RowIndex].Cells[4].Value;
        ms = new MemoryStream(picarr);
        ms.Seek(0, SeekOrigin.Begin);
        PBcompdetailhisphoto.Image = System.Drawing.Image.FromStream(ms);
    }
我得到一个错误:

无法将“System.String”类型的对象强制转换为“System.Byte[]”类型。)

从线路

byte[] picarr = (byte[])DG_Mas_Com_History.Rows[e.RowIndex].Cells[4].Value;

这一行有问题:

His.Photo = oDr[6].ToString();
您需要从数据库中获取以字节为单位的图像,请参见此处