2012-06-15 26 views
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; 

回答