how to retrive image from ms access database using C#

Jun 7 2015 2:21 AM
i want to search image to be stored in binary form in ms access database using C#
 i am enter account no and try to show that person image show in picture box.
my source code blow

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.IO;

using System.Drawing.Imaging;

using System.Data.OleDb;

using Microsoft.VisualBasic;

namespace proposed_embed_system

{

public partial class Form4 : Form

{

public Form4()

{

InitializeComponent();

}

OleDbConnection con;

OleDbCommand cmd;

OleDbDataAdapter adapter;

DataSet ds;

int rno = 0;

MemoryStream ms;

byte[] photo_aray;

private void Form4_Load(object sender, EventArgs e)

{

con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\Embed system\\ATM.mdb");

loaddata();

showdata();

}

void loaddata()

{

adapter = new OleDbDataAdapter("select * from atm", con);

ds = new DataSet();

adapter.Fill(ds, "atm");

}

void showdata()

{

accountBox.Text = ds.Tables[0].Rows[rno][0].ToString();

pictureBox3.Image = null;

if (ds.Tables[0].Rows[rno][4] != System.DBNull.Value)

{

photo_aray = (byte[])ds.Tables[0].Rows[rno][4];

MemoryStream ms = new MemoryStream(photo_aray);

pictureBox3.Image = Image.FromStream(ms);

}

}

private void enterbtn_Click(object sender, EventArgs e)

{

try

{

int n = Convert.ToInt32(Interaction.InputBox("Enter Account No:", "Search", "20", 100, 100));

DataRow drow;

drow = ds.Tables[0].Rows.Find(n);

if (drow != null)

{

rno = ds.Tables[0].Rows.IndexOf(drow);

pictureBox3.Image = null;

if (drow[4] != System.DBNull.Value)

{

photo_aray = (byte[])drow[4];

MemoryStream ms = new MemoryStream(photo_aray);

pictureBox3.Image = Image.FromStream(ms);

}

}

else

MessageBox.Show("Record Not Found");

}

catch

{

MessageBox.Show("Invalid Input");

}

}

 
Please tell me what i wrong with this
my output comes invalid input 

Answers (6)