Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF: Loading JPG file, saving it into MS SQL DB
    text
    copied!<p>I'm new to WPF and programming in general. I set up a dummy db table with one coumn being IMAGE. I now did a WPF window where by clicking a button, a OpenFileDialog appears to load jpg files. When selceting a JPG file and confirming, the image is being displayed in my wpf window. Untill here things work for me. Now that the image is loaded and displayed I want to click on another button to save that image into my SQL database. I have no idea how to do that, I suppose I have to convert the image into binary code, or something? Furthermore I don't have a clue how to do the sql query (INSERT INTO tb_test VALUES('Title', MYIMAGEOBJECT?); ??).</p> <p>also, I should mention, that I already have a connection to the db, excecuting queries is already possible for me.</p> <p>The code I use so far is below, any hint is appreciated!</p> <pre><code> private void openImage() { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = @_imagepath; openFileDialog1.Title = "Browse Image Files"; openFileDialog1.CheckFileExists = true; openFileDialog1.CheckPathExists = true; openFileDialog1.DefaultExt = "jpg"; openFileDialog1.Filter = "JPG files (*.jpg)|*.jpg|All files (*.*)|*.*"; openFileDialog1.FilterIndex = 1; openFileDialog1.RestoreDirectory = true; Nullable&lt;bool&gt; result = openFileDialog1.ShowDialog(); if (result==true) { //display file's path in txt box _txtBxArtwork.Text = openFileDialog1.FileName; // Convert string to image source ImageSourceConverter imgConv = new ImageSourceConverter(); ImageSource imageSource = (ImageSource)imgConv.ConvertFromString(openFileDialog1.FileName); _imagePreview.Source = imageSource; // set new image path setNewImagePath(System.IO.Path.GetDirectoryName(openFileDialog1.FileName)); } } private void setNewImagePath(String newpath) { _imagepath = newpath; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload