Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

how to retrieve picture from MS Access(object OLE) to image control wpf c#?

$
0
0

Hi all, i'm using C# wpf ans MS Access database and my question is how to retrieve a picture from mdb file(saved as byte) to image control and the saving code works fine but the problem is on the retrieve.

////////////////////////////////////////////////////////saving code/////////////////////////////////////////////////////////////////////////////////

private void save_click(object sender, System.Windows.RoutedEventArgs e)
        {
  OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; DataSource=|DataDirectory|\\Location.mdb");
            con.Open();
            try
            {
                OleDbCommand cmd = new OleDbCommand("INSERT INTO vehicles (ID,manufacturer,model,doors,price_per_day,picture) VALUES (?,?,?,?,?,?)", con);
                cmd.Parameters.AddWithValue("?", txtconstructeur.Text);
                cmd.Parameters.AddWithValue("?", txtconstructeur.Text);
                cmd.Parameters.AddWithValue("?", txtmodel.Text);
                cmd.Parameters.AddWithValue("?", cmbdoors.Text);
                cmd.Parameters.AddWithValue("?", txtprix.Text);
                var bits = getJPGFromImageControl(img1.Source as BitmapImage);
                cmd.Parameters.AddWithValue("?", bits);
                cmd.ExecuteNonQuery();
                con.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Erreur", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        public byte[] getJPGFromImageControl(BitmapImage img1)
        {
            MemoryStream memStream = new MemoryStream();
            JpegBitmapEncoder encoder = new JpegBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(img1));
            encoder.Save(memStream);
            return memStream.GetBuffer();
        }

how retrieve it please to C# wpf image control named imagedata

Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>