
Untitled
By: a guest on
Aug 8th, 2012 | syntax:
None | size: 1.38 KB | hits: 7 | expires: Never
How can I add a picture to a Database using DataBindign
private void simpleButton5_Click_1(object sender, EventArgs e)
{
try
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
picture.ImageLocation = openFileDialog1.FileName;
imgData = File.ReadAllBytes(openFileDialog1.FileName);
}
}
catch (Exception ex)
{
// Could not load the image - probably related to Windows file system permissions.
XtraMessageBox.Show("Cannot display the image.n You may not have permission to read the file, or " +
"it may be corrupt.nnReported error: " + ex.Message);
}
}
private void ReadFileFromDatabase()
{
byte[] fileData = null;
string selectSql = "SELECT FILE_DATA FROM BLOBTEST WHERE FILE_ID=1";
OracleConnection con = new OracleConnection(conString);
OracleCommand cmd = new OracleCommand(selectSql, con);
try
{
con.Open();
using (IDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
fileData = (byte[])reader["FILE_DATA"];
//do your operations with fileData here
}
}
}
finally
{
con.Close();
}
}