Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-04-15
3
Medium Priority
?
164 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

604 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