How do I get an image file into SQL DB and display in bound DataGridViie
Posted on 2009-04-15
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"
DataRowView currentRow = (DataRowView)imageTestBindingSource.Current;
MemoryStream ms = new MemoryStream();
currentRow["image"] = ms.GetBuffer
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.Cells.Value = myIcon;
Not quite sure where I'm going wrong.