Solved

How do I get an image file into SQL DB and display in bound DataGridViie

Posted on 2009-04-15
3
160 Views
Last Modified: 2013-12-17
I have created a test database with a column of type "image" and bound it to a "DataGridViewImageColumn" column on a DataGridView.

Our user, using on OpenDialog, selects a file, and from that I get the "Icon" asscoiated with that file and save in a variable: "myIcon"

I need to save this Icon image, not a link to it, in the DB and also display it on the "DataGridView"

The code:

  imageTestBindingSource.AddNew();
  DataRowView currentRow = (DataRowView)imageTestBindingSource.Current;
  MemoryStream ms = new MemoryStream();
  myIcon.Save(ms);
  currentRow["image"] = ms.GetBuffer
  imageTestBindingSource.EndEdit();
  imageTestTableAdapter.Update(xtracTechSpecDataSet.ImageTest);          
  this.imageTestTableAdapter.Fill(this.xtracTechSpecDataSet.ImageTest);

appears to put data into the DB, but I get a "DataGridView Default Error Dialog" as soon as this last bit of code runs.

It would seem that the DataGridView does'nt know how to display the Icon.

On a side issue I am able to get the "icon" image file to display directly to an unbound "DataGridViewImageColumn" using:

  imageTestDataGridView.Rows[0].Cells[0].Value = myIcon;

Not quite sure where I'm going wrong.
0
Comment
Question by:xtrac-support
  • 2
3 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 24311895
Retrieve Images from a SQL database for display in an Asp.Net Datagrid
http://www.odetocode.com/Articles/172.aspx

Bind Image from Database to DataGrid (web Application)
http://www.codeproject.com/KB/aspnet/ImageFromDBtoGrid.aspx
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 24311897
Retrieving Images from SqlServer and displaying in a DataGrid - ASP .NET
http://aspalliance.com/articleViewer.aspx?aId=141&pId
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question