Solved

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

Posted on 2009-04-15
3
154 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
Comment Utility
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
Comment Utility
Retrieving Images from SqlServer and displaying in a DataGrid - ASP .NET
http://aspalliance.com/articleViewer.aspx?aId=141&pId
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now