Blue Theme Orange Theme Green Theme Red Theme
 
Click Here for 3 Month Free of ASP.NET Hosting!
Skip Navigation Links
C# Corner Home
Forum Home
Latest 50
Unanswered
Win $500 Cash
All Time Leaders
Jump to CategoryExpand Jump to Category
Login 
    Welcome Guest!
 Search Forum For :  
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id:
Password:  
Forgot Password | Forgot UserName
   Home » C# Language » Retrieve image path from MYSQL and display one by one, Please help!
       
Author Reply
zhang
posted 5 posts
since Nov 03, 2009 
from

 Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/3/2009 11:08:49 PM       
I have saved all the image path in mysql, just like this..(MYSQL is in LINUX system) No name 1 /root/images/baidu.gif 2 /root/images/train.gif 3 /root/images/flower.gif 4 ....... 5 ........ I want to retrieve these path and display the images one by one on the winform MySql.Data.MySqlClient.MySqlConnection conn; string myConnectionString; myConnectionString = "server=11.11.11.11;uid=root;" + "pwd=;database=image;"; BindingSource binds = new BindingSource(); conn = new MySql.Data.MySqlClient.MySqlConnection(); conn.ConnectionString = myConnectionString; conn.Open(); MySqlDataAdapter da = new MySqlDataAdapter("select * from spad", conn); DataSet ds = new DataSet(); da.Fill(ds, "spad"); string loadPic = "SELECT iname from spad"; string fullpath = string.Format("\\root\\images\\{0}", loadPic); this.pictureBox1.Image = Image.FromFile(fullpath); conn.Close(); What should I do now? Thanks very much!!!
niki d
posted  220 posts
since  Oct 27, 2006 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/3/2009 11:28:43 PM       

Hi friend;
 
Change your code as follows.
 
 
MySql.Data.MySqlClient.MySqlConnection conn;
string myConnectionString;
myConnectionString =
"server=11.11.11.11;uid=root;" + "pwd=;database=image;";
BindingSource binds = new BindingSource();
conn =
new MySql.Data.MySqlClient.MySqlConnection();
conn.ConnectionString = myConnectionString; conn.Open();
MySqlDataAdapter da =
new MySqlDataAdapter("select * from spad", conn);
DataSet ds = new DataSet();
da.Fill(ds,
"spad");
DataTable dt = da.Tables[0];
int i = 1;
PictureBox xff = new PictureBox();
foreach(DataRow dr in dt.Rows)
{
string filepath = dr["iname"].ToString();
string filename = Path.GetFileName(filepath);
Image myimage = Image.FromFile(string.Format("\\root\\images\\{0}", filename));
//Now you can set 'myimage' to the picture box.
}
conn.Close();
 
 
Do you have a set of picture boxes? Or you have only one picture box? Anyway you can set the image 'myimage' to the picture box.
 
pictureBox1.Image = myimage;
 
Hope this helps. If so please accept my answer.
 
Thanks

 

Niki

niki d
posted  220 posts
since  Oct 27, 2006 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/3/2009 11:58:27 PM       

Hi friend,
 
I felt, earlier reply is incomplete as it does not contain creating the picture boxes list. So ignore the previous reply and focus on this.
 
MySql.Data.MySqlClient.MySqlConnection conn;
string myConnectionString;
myConnectionString =
"server=11.11.11.11;uid=root;" + "pwd=;database=image;";
BindingSource binds = new BindingSource();
conn =
new MySql.Data.MySqlClient.MySqlConnection();
conn.ConnectionString = myConnectionString; conn.Open();
MySqlDataAdapter da =
new MySqlDataAdapter("select * from spad", conn);
DataSet ds = new DataSet();
da.Fill(ds,
"spad");
DataTable dt = da.Tables[0];
System.Collections.
ArrayList
imagelist = new System.Collections.ArrayList();
int i = 1;
foreach(DataRow dr in dt.Rows)
{
string filepath = dr["iname"].ToString();
string filename = Path.GetFileName(filepath);
Image myimage = Image.FromFile(string.Format("\\root\\images\\{0}", filename));
PictureBox temp = new PictureBox();
temp.Name =
string.Format("pictureBox{0}",i.ToString());

temp.Image = myimage;

imagelist.Add(temp);
i++;
}
conn.Close();
PictureBox
[] pictureboxarray = (PictureBox[])imagelist.ToArray(typeof(PictureBox));
 
This creates a set of picture boxes named pictureBox1, pictureBox2,.... and sets the images to them. And adds it to an array.
 
So if you want to access those picture boxes you can do that as you access a normal array.
 
If you find any issue in my code, pls ask. And pls spend few seconds to accept this answer if this helps you.
 
 

Niki

zhang
posted  5 posts
since  Nov 03, 2009 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/4/2009 1:42:23 AM       
Thanks very much, but how can the image display at one position(maybe in only 1 picturebox), like 1.jpg display 3 sec, then 2.jpg display 3 sec, then 3.jpg display 3 sec.... and loop forever... and I do not know how many image are there, because the database will be update soon.
niki d
posted  220 posts
since  Oct 27, 2006 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/4/2009 2:16:35 AM       

Hi friend,
 
Then we don't have to create picture boxes and arrays.  You need only one picture box.
But you have to create another thread.

Niki

niki d
posted  220 posts
since  Oct 27, 2006 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/4/2009 2:16:36 AM       

Hi friend,
 
Then we don't have to create picture boxes and arrays.  You need only one picture box.
But you have to create another thread. If

Niki

niki d
posted  220 posts
since  Oct 27, 2006 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/4/2009 2:16:37 AM       

Hi friend,
 
Then we don't have to create picture boxes and arrays.  You need only one picture box.
But you have to create another thread. If you

Niki

niki d
posted  220 posts
since  Oct 27, 2006 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/4/2009 2:16:39 AM       

Hi friend,
 
Then we don't have to create picture boxes and arrays.  You need only one picture box.
But you have to create another thread. If you want

Niki

niki d
posted  220 posts
since  Oct 27, 2006 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/4/2009 2:16:39 AM       

Hi friend,
 
Then we don't have to create picture boxes and arrays.  You need only one picture box.
But you have to create another thread. If you want my

Niki

niki d
posted  220 posts
since  Oct 27, 2006 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/4/2009 2:16:42 AM       

Hi friend,
 
Then we don't have to create picture boxes and arrays.  You need only one picture box.
But you have to create another thread. If you want my help ont

Niki

niki d
posted  220 posts
since  Oct 27, 2006 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/4/2009 2:16:43 AM       

Hi friend,
 
Then we don't have to create picture boxes and arrays.  You need only one picture box.
But you have to create another thread. If you want my help on

Niki

niki d
posted  220 posts
since  Oct 27, 2006 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/4/2009 2:16:44 AM       

Hi friend,
 
Then we don't have to create picture boxes and arrays.  You need only one picture box.
But you have to create another thread. If you want my help

Niki

niki d
posted  220 posts
since  Oct 27, 2006 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/4/2009 2:16:44 AM       

Hi friend,
 
Then we don't have to create picture boxes and arrays.  You need only one picture box.
But you have to create another thread. If you want my help on that

Niki

niki d
posted  220 posts
since  Oct 27, 2006 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/4/2009 2:16:45 AM       

Hi friend,
 
Then we don't have to create picture boxes and arrays.  You need only one picture box.
But you have to create another thread. If you want my help on that let

Niki

niki d
posted  220 posts
since  Oct 27, 2006 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/4/2009 2:16:45 AM       

Hi friend,
 
Then we don't have to create picture boxes and arrays.  You need only one picture box.
But you have to create another thread. If you want my help on that let me

Niki

niki d
posted  220 posts
since  Oct 27, 2006 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/4/2009 2:16:49 AM       

Hi friend,
 
Then we don't have to create picture boxes and arrays.  You need only one picture box.
But you have to create another thread. If you want my help on that let me know.

Niki

zhang
posted  5 posts
since  Nov 03, 2009 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/4/2009 2:27:48 AM       
Thanks very much!!I need you help, pleaseeee^_^
niki d
posted  220 posts
since  Oct 27, 2006 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/4/2009 4:31:14 AM   Accepted Answer    

Hi friend,
 
You dont need to go for threading to that. With a timer you can do that.
 
 
Add a trimer to your class.
 
Then set an interval.
 
For your case it's 3000. ( 3 seconds. 3000 in milli seconds.)
 
 
Then write the code as follows. In tbhe tick event of the timer you can update the picture box.
 
 
//Define two global variables.

private
int index = 0;
private
string[] imagelist;
private
void button1_Click(object sender, EventArgs e)
{
string myConnectionString;
myConnectionString =
"server=11.11.11.11;uid=root;" + "pwd=;database=image;";
BindingSource binds = new BindingSource();
conn =
new MySql.Data.MySqlClient.MySqlConnection();
conn.ConnectionString = myConnectionString; conn.Open();
MySqlDataAdapter da =
new MySqlDataAdapter("select * from spad", conn);
DataSet ds = new DataSet();
da.Fill(ds,
"spad");
DataTable dt = da.Tables[0];
if ((dt == null) || (dt.Rows.Count == 0))
{
MessageBox.Show("No Data");
return;
}
//Now you have the data table.
//Get the list of image names.
imagelist =
new string[dt.Rows.Count];
for(int i =0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
string filepath = dr["iname"].ToString();
string filename = Path.GetFileName(filepath);
imagelist[i] =
string.Format("\\root\\images\\{0}", filename);
}
conn.Close();
timer1.Start();
//Start the timer.
}

private
void timer1_Tick(object sender, EventArgs e)
{
if (imagelist == null)
return;
if (imagelist.Length < index + 1)
{
timer1.Stop();
return;
}
Image myimage = Image.FromFile(imagelist[index]);
pictureBox1.Image = myimage;
index++;
}

 
 
 

Niki

zhang
posted  5 posts
since  Nov 03, 2009 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/4/2009 5:02:43 AM       
Thanks very very very much!! MySqlDataAdapter da = new MySqlDataAdapter("select * from spad", conn); DataSet ds = new DataSet(); da.Fill(ds, "spad"); DataTable dt = da.Tables[0]; (da.Tables[0]has error.) Error 1 'MySql.Data.MySqlClient.MySqlDataAdapter' does not contain a definition for 'Tables' and no extension method 'Tables' accepting a first argument of type 'MySql.Data.MySqlClient.MySqlDataAdapter' could be found (are you missing a using directive or an assembly reference?) is it ds.Tabless[0]?
niki d
posted  220 posts
since  Oct 27, 2006 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/4/2009 5:40:04 AM       

ya friend,
 
small mistake in typing. should be corrected as ds.Tables[0].
 
if you find my naswer useful do not forget to accpet it pls.. :)

Niki

zhang
posted  5 posts
since  Nov 03, 2009 
from 

 Re: Retrieve image path from MYSQL and display one by one, Please help!
  Posted on: 11/4/2009 8:26:18 PM       
Hi Dear friend !thanks very much for your help!!!!!!!
       
Sponsored by
Become a Sponsor
Developer-Ready ASP.NET 2.0 Web Hosting with 3 MONTHS FREE
Now supporting .NET 3.0 Framework with Windows Workflow Foundation, Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), windows CardSpace (WCS)! Providing more flexibility for Developers with Web Services Support and a User/Permission Manger. Also supporting MS SQL 2005/2000 with Real-Time Backups, FREE Automated Attach .MDF Tool, FREE SQL Restore and Shrink SQL DB Tools, and SQL
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010
Microsoft Visual Studio 2010 offers more to developers than any other Visual Studio release. Work more productively and collaboratively-with greater control over your work at every step. The Beta 2 can give you a head start on achieving efficiency.

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Advertise with us
Current Version: 3.2009.8.27
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved