سلام
خودم یه برنامه دارم مینویسم که همین کار رو میکنه فرم من اینطوریه :
و این هم کدهاش :
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "\\school.accdb;Jet OLEDB:Database Password=c#2008");
OleDbCommand com = new OleDbCommand();
OleDbDataAdapter da = new OleDbDataAdapter();
string sql;
int count = 1, minpicIP = 1, maxpicIP = 1;
private void displyBtn_Click(object sender, EventArgs e)
{
try
{
com.Connection = con;
con.Open();
sql = "select COUNT(*) FROM pictures ";
com.CommandText = sql;
count = Convert.ToInt32((com.ExecuteScalar()).ToString());
sql = "select MIN(idpic) FROM pictures ";
com.CommandText = sql;
minpicIP = Convert.ToInt32((com.ExecuteScalar()).ToString());
t = minpicIP;
sql = "select MAX(idpic) FROM pictures ";
com.CommandText = sql;
maxpicIP = Convert.ToInt32((com.ExecuteScalar()).ToString());
con.Close();
timer1.Interval = int.Parse(timedisplay.Text) * 10;// ثانیه
timer1.Enabled = true;
}
catch { Exception g; }
}
int t = 1;
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Interval = int.Parse(timedisplay.Text) * 1000;// ثانیه
if (t <= count)
{
try
{
DataTable dt = new DataTable();
string query = "select pictures,picname from pictures where idpic=" + t;
com.CommandText = query;
com.Connection = con;
da.SelectCommand = com;
con.Open();
da.Fill(dt);
com.ExecuteNonQuery();
con.Close();
byte[] arrPic = (byte[])(dt.Rows[0]["pictures"]);
MemoryStream ms = new MemoryStream(arrPic);
pictureBox1.Image = Image.FromStream(ms);
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
label7.Text = dt.Rows[0]["picname"].ToString();
//فراخوانی جهت تصویر بعدی
query = "select top 1 IDPIC from pictures where idpic>" + t;
com.CommandText = query;
com.Connection = con;
da.SelectCommand = com;
con.Open();
int t1 = Convert.ToInt32((com.ExecuteScalar()).ToString());
con.Close();
t = t1;
}
catch { con.Close(); return; }
}
}
private void nextpic_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
try
{
string query = "select min(IDPIC) from pictures where IDPIC >" + t;
DataTable dt = new DataTable();
com.CommandText = query;
com.Connection = con;
da.SelectCommand = com;
con.Open();
int t1 = Convert.ToInt32((com.ExecuteScalar()).ToString());
//فراخوانی جهت تصویر بعدی
query = "select min(IDPIC) from pictures where IDPIC > " + t1;
dt = new DataTable();
com.CommandText = query;
com.Connection = con;
da.SelectCommand = com;
t1 = Convert.ToInt32((com.ExecuteScalar()).ToString());
con.Close();
t = t1;
}
catch { con.Close(); return; }
if (t >= count) t = count;
}
private void perviuspic_Click(object sender, EventArgs e)//DESC
{
timer1.Enabled = true;
try
{
string query = "select max(IDPIC) from pictures where IDPIC<" + t;
DataTable dt = new DataTable();
com.CommandText = query;
com.Connection = con;
da.SelectCommand = com;
con.Open();
int t1 = Convert.ToInt32((com.ExecuteScalar()).ToString());
//فراخوانی جهت تصویر قبلی
query = "select max(IDPIC) from pictures where IDPIC<" + t1;
dt = new DataTable();
com.CommandText = query;
com.Connection = con;
da.SelectCommand = com;
t1 = Convert.ToInt32((com.ExecuteScalar()).ToString());
con.Close();
t = t1;
}
catch { con.Close(); return; }
if (t < 1) t = 1;
}
private void stopbtn_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
}
private void timedisplay_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(char.IsDigit(e.KeyChar)) ) e.Handled = true;
if (e.KeyChar == ' '|| e.KeyChar=='\b') e.Handled = false;
}