Solved

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

Posted on 2009-04-15
3
161 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

726 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