Solved

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

Posted on 2009-04-15
3
159 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

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 article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

772 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