我在 Datagrid 的图片框中显示图像时遇到问题。我使用了 sqlconnection 并使用 sqldatareader 获取数据。我将图片以systembyte格式保存在sql server中,但是当我单击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; }
}
}
数据网格点击事件
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;