Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to develop an desktop app to save and retrieve details from database, but am having a little hitch
am getting errors in my code, kindly advice below are the required code

xaml
XML
<grid>
        <textbox horizontalalignment="Left" height="23" margin="144,28,0,0" textwrapping="Wrap" x:name="TbxId" verticalalignment="Top" width="193" xmlns:x="#unknown" />
        <textbox horizontalalignment="Left" height="23" margin="144,134,0,0" textwrapping="Wrap" x:name="TbxFn" verticalalignment="Top" width="193" xmlns:x="#unknown" />
        <textbox horizontalalignment="Left" height="23" margin="144,77,0,0" textwrapping="Wrap" x:name="TbxLn" verticalalignment="Top" width="193" xmlns:x="#unknown" />
        <Label Content="Student ID" HorizontalAlignment="Left" Margin="10,28,0,0" VerticalAlignment="Top" Width="101"/>
        <Label Content="Last Name" HorizontalAlignment="Left" Margin="10,134,0,0" VerticalAlignment="Top" Width="101"/>
        <Label Content="First Name" HorizontalAlignment="Left" Margin="10,77,0,0" VerticalAlignment="Top" Width="101"/>
        <Button x:Name="BtnSave" Content="Save" HorizontalAlignment="Left" Margin="23,206,0,0" VerticalAlignment="Top" Width="75" />
        <Button x:Name="BtnBrowse" Content="Browse" HorizontalAlignment="Left" Margin="149,206,0,0" VerticalAlignment="Top" Width="75" Click="Save"/>
        <Button x:Name="BtnShow" Content="Show" HorizontalAlignment="Left" Margin="294,206,0,0" VerticalAlignment="Top" Width="75"/>
        <windowsformshost grid.column="0" margin="448,28,75,243">
            <wf:picturebox x:name="pictureBox1" height="150" width="150" sizemode="StretchImage" xmlns:x="#unknown" xmlns:wf="#unknown" />
        </windowsformshost>
</grid>

cs
C#
private void Browse(object sender, RoutedEventArgs e)
        {
            SqlConnection cn = SqlConnection(global::DatabaseApp.Properties.Settings.Default.Database1ConnectionString);

            try 
            {
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.Filter = "JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif|All Files(*.*)|*.*";
                dlg.Title = "Select Student Picture";
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    imgLoc = dlg.FileName.ToString();
                    picStu.ImageLocation = imgLoc;
                }
            }
            catch(Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message);
            }
        }

Thank you
Posted
Updated 29-Mar-15 6:17am
v2
Comments
Richard MacCutchan 29-Mar-15 12:29pm    
You create a database connection string, and then use OpenFileDialog to find the name of an image file. What is the connection between the two actions? You also need to tell us what the errors are, and where they occur.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900