2
Answers

insert browse image wpf

I need to insert an image to MySql using WPF.
The image can be selected value of browse&choose button.
Only I don't have enough experience with browse&choose image insertion.
byte[] ImageBytes = (byte[])PredictedHelpNeededArea;
Below is my code:
<Button x:Name="btnBrowse" Content="Browse" Click="btnBrowse_Click"/>
<Button x:Name="btnInsert" Content="Insert" Click="btnInsert_Click"/>
<Image Name="MyImage"></Image>
private void btnInsert_Click(object sender, RoutedEventArgs e)
{
{

if (MyImage.Source != null)
{
MySqlConnection con = new MySqlConnection(constr);
MySqlCommand cmd = new MySqlCommand("INSERT INTO images (Image_BLOB) VALUES (@ImageSource)", con);
byte[] ImageBytes = (byte[])PredictedHelpNeededArea;
cmd.Parameters.Add("@ImageSource", MySqlDbType.Blob, ImageBytes.Length).Value = ImageBytes;
con.Open();
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
MessageBox.Show("Image Inserted");
}

}
else
{
MessageBox.Show("Choose an image");
}
}

}

private void btnBrowse_Click(object sender, RoutedEventArgs e)
{
Stream checkStream = null;
Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
openFileDialog.Multiselect = false;
openFileDialog.Filter = "All Image Files | *.*";
if ((bool)openFileDialog.ShowDialog())
{
try
{
if ((checkStream = openFileDialog.OpenFile()) != null)
{
MyImage.Source = new BitmapImage(new Uri(openFileDialog.FileName, UriKind.Absolute));
MessageBox.Show("Successfully done");
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}

}
else
{

MessageBox.Show("Problem occured, try again later");

}
}
Answers (2)
0
Suthish Nair

Suthish Nair

NA 31.7k 4.6m 14y
ok.. but i want to know the above script i posted giving correct output or not?
0
Naresh Babu Gopavaram

Naresh Babu Gopavaram

NA 256 203.5k 14y
no
 i want in linq 
0
Suthish Nair

Suthish Nair

NA 31.7k 4.6m 14y

 resolved?

 will this not work...

 select rm.doc,rm.name,pd.address, cd.vaolum 'volumename'
 From RegistrationMaster RM inner join Partydetails pd 
 on rm.doc=pd.doc 
 inner join DocumentInfo DI 
 on rm.cdcode=DI.cdcode
 inner join CDMaster cd 
 on di.code = cd.code