0

I have the following code

string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + txtFileLocation.Text;

using (DbConnection conn = new OleDbConnection(connectionString))
        {
            conn.Open();

            DbCommand command = conn.CreateCommand();
            string idfield = txtIDField.Text;                
            string picfield = txtPictureField.Text;              

            command.CommandText = "select " + idfield + ", " + picfield + " from " + selectedTable;
            command.CommandType = CommandType.Text;

            DbDataReader reader = command.ExecuteReader();    
            gridResults.DataSource = reader;                

            conn.Close();

        }

The database is an access database as u might have seen from the connection string, also the database I was provided with store their images in the database, as Image attachment.

Whenever I load the grid it shows random stuff :( eg. One random moment Another Wooow... there's another one

I am not familiar with the wiring up of a database so this might be an easy question, how do I enable my picture list in my form?

GatesReign
  • 826
  • 1
  • 9
  • 23
  • I do not think you can do this with OleDB http://stackoverflow.com/questions/11819247/reading-attached-files-from-database-using-ole-db/11819599#11819599 – Fionnuala Jan 16 '13 at 17:22
  • @Remou-So there is no work around for this? Maybe save images to filesystem then reading from that? – GatesReign Jan 16 '13 at 18:24
  • Yes, you can do that with DAO or ADO recordset. This is the only way I have found, I am not saying it is the last word. It is not at all difficult within MS Access http://stackoverflow.com/questions/13902775/display-multiple-attachments-in-microsoft-access-2010-forms-and-reports/13904836#13904836 You might be able to use the query with your forms. The attachment type itself is a recordset that contains a number of objects, so you certainly cannot display that. As you can see from both my links, you can reference the contained recordset. – Fionnuala Jan 16 '13 at 19:36
  • @Remou I see you have quiet a bit of experience with Access, would you by any chance have or know of some reference on how to store images to the filesystem? – GatesReign Jan 16 '13 at 20:22
  • To my mind, there is no really satisfactory way to store images. Attachment is pretty good if you are working within MS Access, you can use an ADODB stream to write to OLE Object and return images to disk, but OLE Objects can get weird. It may be pure prejudice, but I still think that you are better off just storing a file location for images and keeping them on disk. – Fionnuala Jan 16 '13 at 20:32

0 Answers0