0
我有一个问题,从Datagrid中的图片框中显示图像。我使用sqlconnection并使用sqldatareader获取数据。我保存的图片中systembyte格式在SQL Server中,但是当我点击DataGrid中第i行不能显示图片在c#中使用sqldatareader Datagrid在pictureBox中显示图像
请帮助我
LOAD FROM读者值的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 Click事件
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;