.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

how to retrieve image from MS Access database to datagridview to the picturebox

Posted By: tina     Posted Date: July 15, 2012    Points:5   Category :C#
private void Form1_Load(object sender, EventArgs e)
{
this.BackColor = System.Drawing.Color.LightBlue;// change the form's background colour

OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=K:\FYP_ Prgms\DatabaseConnection2\DatabaseConnection2\Database 4.accdb");
conn.Open();
OleDbDataAdapter SDA = new OleDbDataAdapter("SELECT * from [Memo]", conn);
//OleDbCommandBuilder builder = new OleDbCommandBuilder(SDA);
DataTable dt = new DataTable();
SDA.Fill(dt);
dataGridView1.DataSource = dt;

}
int i;
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
i = dataGridView1.SelectedCells[0].RowIndex;
textBox1.Text = dataGridView1.Rows[i].Cells[0].Value.ToString();
textBox2.Text = dataGridView1.Rows[i].Cells[1].Value.ToString();
textBox3.Text = dataGridView1.Rows[i].Cells[2].Value.ToString();
textBox5.Text = dataGridView1.Rows[i].Cells[3].Value.ToString();
pictureBox1.ImageLocation = dataGridView1.Rows[i].Cells[4].Value.ToString();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
when i click across the row datagridview; no image being displayed in the picturebox. i inserted (OLE Object) BitMap Image into the column named "Image" of MS Access database.
what's the pblm? any coding for poctureBox1?
Thanks.

Responses
Author: Narayanan             
Posted Date: August 03, 2012     Points: 20   

Hi,
try this
Old Code:
pictureBox1.ImageLocation = dataGridView1.Rows[i].Cells[4].Value.ToString();

New Code
pictureBox1.Image = (Image)dataGridView1.Rows[i].Cells[4].Value;


Regards, Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend