Here is a problem which doesn't un-sticks from me ,,i have a column of
person_image varbinary(max)at my table in MS Sqlserver-2012,, now the thing is i have to bind this column to my datagridview in windows forms, actually while before binding this binary information to Datagridview ,It's needs to be converted into images and then, i have to bind them to datagridview as shows as images in it's column,,i also tried with datagridviewimagecolumn...but it was binding with broken images,not actually with real images..here is another point to remember..i don't have the paths of images,i have only binary images at my table in Back-End..Infact i could get the paths of images...but is that is the only thing to do...did i can't convert them(binary) in to images before binding..?I am trying to fix this for long 2 days..but what the code found in different sites was getting complicated in the way of modifying my whole application code...
Here is the code which i follows and also it was throwing an exception that mentioning
an object reference was not set to an instance at try block
public void BindDataGrid()
{
string bindQuery = "select * from employee";
_cmd = new SqlCommand();
_cmd.CommandText = bindQuery;
_cmd.Connection = _con;
_con.Open();
_da = new SqlDataAdapter(_cmd);
_ds = new DataSet();
DataGridViewImageColumn dgi = new DataGridViewImageColumn();
dgi.Name = "image";
dgi.HeaderText = "Person_image";
dgi.ImageLayout = DataGridViewImageCellLayout.Zoom;
try
{
dgi.Image = bytearraytoimage((byte[])_ds.Tables["employee"].Rows[1]["image"]);
}
catch (Exception x)
{
MessageBox.Show(x.Message);
}
dataGridView1.Columns.Insert(0,dgi);
_con.Close();
_da.Fill(_ds);
dataGridView1.DataSource = _ds.Tables[0];
}
private Image bytearraytoimage(byte[] b)
{
MemoryStream ms=new MemoryStream(b);
Image img=Image.FromStream(ms);
return img;
}
private void Form1_Load(object sender, EventArgs e)
{
BindDataGrid();
}
I will be so thankful,, if i have a smart code to achieve this task....any suggestions..please....go-on...