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 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.
|
|
|
|
|
|
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 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 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 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 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 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 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 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 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 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 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 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.
|
|
|
|
|
|
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++;
}
|
|
|
|
|
|
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.. :)
|
|
|
|
|
|
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!!!!!!!
|
|
|
|
|
|