Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to retrieve images from SQL Server database into WPF form?? (LINQ, Databinding, SQL)
    primarykey
    data
    text
    <p>I have a cheapo window where I insert data into a database. My db-columns are the following:</p> <pre><code>col name(varchar), col age (int), col photo (image) (all NOT NULL) </code></pre> <p>Now I want to retrieve the info from the db into my window. I have a listbox where I retrieve the names like this (LINQ query)</p> <pre><code>public void updateListbox(){ DataClasses1DataContext dc = new DataClasses1DataContext(); var query = from s in dc.tablename select s; _listBox1.ItemsSource = query.ToList(); } </code></pre> <p>My xaml code for binding looks like this:</p> <pre><code>&lt;ListBox ... DisplayMemberPath="Name"/&gt; </code></pre> <p>so the names are now being displayed in the listbox. </p> <p>My next step is to display the image/photo of the representative person that is selected in the listbox on my window/form. I did it with the age property in a textblock like this:</p> <pre><code>&lt;TextBlock ... Text="{Binding ElementName=_listBox1, Path=SelectedItem.Age}" /&gt; </code></pre> <p>but I have no idea how to retrieve the image into my wpf window.</p> <p>I save the image like this</p> <pre><code>byte[] image = File.ReadAllBytes(@imagepath); ... sqlcommandobject.Parameters.Add(new SqlParameter("@Photo", image)); ... </code></pre> <p>by using openFileDialog to load the image(-path) before insterting into the db. Just retrieving is my problem now. I really would like to keep the binding as simple as it is at this moment, but I guess there is no way to retrieve the image by doing something like this:</p> <pre><code>&lt;Image ... Source="{Binding ElementName=_listBox, Path=SelectedItem.Photo}" /&gt; </code></pre> <p>As the binary data has to be converted back to an image object(?), and I'm lost on how to do that and conbine this with the bindings. Anyone have an idea? </p> <p>Thanks for reading!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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