Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 8th, 2012  |  syntax: None  |  size: 1.38 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How can I add a picture to a Database using DataBindign
  2. private void simpleButton5_Click_1(object sender, EventArgs e)
  3.     {
  4.         try
  5.         {
  6.             if (openFileDialog1.ShowDialog() == DialogResult.OK)
  7.             {
  8.                 picture.ImageLocation = openFileDialog1.FileName;
  9.  
  10.                 imgData = File.ReadAllBytes(openFileDialog1.FileName);
  11.             }
  12.         }
  13.         catch (Exception ex)
  14.         {
  15.             // Could not load the image - probably related to Windows file system permissions.
  16.             XtraMessageBox.Show("Cannot display the image.n You may not have permission to read the file, or " +
  17.                 "it may be corrupt.nnReported error: " + ex.Message);
  18.         }
  19.     }
  20.        
  21. private void ReadFileFromDatabase()
  22.     {
  23.         byte[] fileData = null;
  24.  
  25.         string selectSql = "SELECT FILE_DATA FROM BLOBTEST WHERE FILE_ID=1";
  26.  
  27.         OracleConnection con = new OracleConnection(conString);
  28.         OracleCommand cmd = new OracleCommand(selectSql, con);
  29.  
  30.         try
  31.         {
  32.             con.Open();
  33.             using (IDataReader reader = cmd.ExecuteReader())
  34.             {
  35.                 while (reader.Read())
  36.                 {
  37.                     fileData = (byte[])reader["FILE_DATA"];
  38.                     //do your operations with fileData here
  39.                 }
  40.             }
  41.         }
  42.         finally
  43.         {
  44.             con.Close();
  45.         }
  46.     }