hi ...
my Database (Access) have 3 fields (Pic, Sub, Date) ---> Pic type : OLE object
how to send fields (Database Access) in Arrey ...
then with button (Next / Perview) show Pic in a pictureBox and label ?
my project is PicGallery :)
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Aug 15, 2014, 1:47 PM
ghasem dehPosted Aug 30, 2014, 2:17 PM
VulpesPosted Aug 30, 2014, 11:34 AM
Try making the highlighted changes:
}
index = 0;
if (picList.Count > 0)
{
Next_Click(null, null);
}
else
{
pictureBox1.Image = null;
}
}
ghasem dehPosted Aug 30, 2014, 10:12 AM
VulpesPosted Aug 30, 2014, 7:01 AM
Try putting it in textBox1_Leave instead.
ghasem dehPosted Aug 30, 2014, 3:23 AM
this code NO error ... But not happen !
VulpesPosted Aug 29, 2014, 4:19 PM
Worse still, as 'com' is defined at class level, a new parameter will be added each time the TextChanged event is fired.
Ideally, this code should be in a button_Click handler but you could also put it in textBox1's Leave handler so that it won't be executed until the user has finished typing and moved the input focus to a new control.
I'd also make some changes:
1. Insert this line at the beginning so the code won't execute if the textbox is blank:
if(textBox1.Text.Trim() == "") return;
2. Just before this line:
3. Make sure there's no superfluous whitespace by replacing this line:
ghasem dehPosted Aug 29, 2014, 3:34 PM
VulpesPosted Aug 29, 2014, 2:59 PM
ghasem dehPosted Aug 29, 2014, 2:47 PM
VulpesPosted Aug 29, 2014, 12:11 PM
com.Parameters.AddWithValue("a", textBox1.Text);
ghasem dehPosted Aug 29, 2014, 12:07 PM
VulpesPosted Aug 29, 2014, 11:39 AM
ghasem dehPosted Aug 29, 2014, 11:07 AM
this ERROR
VulpesPosted Aug 29, 2014, 10:08 AM
What error are you getting?
ghasem dehPosted Aug 29, 2014, 6:23 AM
i use this code :
string cmdString = "SELECT Pic, Sub, Alb FROM Aks WHERE Alb=@a";
com.parameters.AddWithValue("@a", textBox1.Text);
but --> ERROR !
i want display pic Based on Album name ...
VulpesPosted Aug 27, 2014, 7:30 PM
However, personally, I never try to remember stuff such as this. I just work out the logic from first principles each time it's needed. That way I can deal with any variations that might occur as you usually find that no two situations in computing are exactly the same.
ghasem dehPosted Aug 27, 2014, 9:46 AM
how to me learn it ?
VulpesPosted Aug 26, 2014, 3:26 PM
ghasem dehPosted Aug 26, 2014, 1:13 PM
VulpesPosted Aug 26, 2014, 12:21 PM
ghasem dehPosted Aug 26, 2014, 11:34 AM
Vulpes you are here ?
this project (TEST) ... Next key OK but Perview key when click on (last image in array) error !
if 10 image in database , Perview from image 9 ... ok BUT from image 10 send erro !
VulpesPosted Aug 16, 2014, 6:49 AM
ghasem dehPosted Aug 16, 2014, 12:03 AM
i write this code to Perview Key :
pictureBox1.Image = picList[index].Pic;
label1.Text = picList[index].Sub;
label2.Text = picList[index].Alb;
index--;
if (index <= picList.Count) index = 0;
But only a picture to go back ... error
ghasem dehPosted Aug 15, 2014, 11:42 AM
this my project
I'm confused ... please checked !
VulpesPosted Aug 15, 2014, 11:03 AM
var picList = new List
should be:
The warning should now go away.
ghasem dehPosted Aug 15, 2014, 10:45 AM
public static string Albumstring = string.Format(@"Provider = Microsoft.Jet.OLEDB.4.0;Data Source = {0}\Data.mdb", Application.StartupPath.ToString());
OleDbConnection con = new OleDbConnection(Albumstring);
OleDbCommand com = new OleDbCommand();
and change (Date) to (Alb = Text) ...
Error Pic
and :
private List
Warning 1 Field 'Scanner_Test.Form2.picList' is never assigned to, and will always have its default value null
VulpesPosted Aug 15, 2014, 9:46 AM
The 'i' should be 'index':
ghasem dehPosted Aug 15, 2014, 9:25 AM
----------------------------------------
int i;
pictureBox1.Image = picList[i].Pic;
lblSub.Text = picList[i].Sub;
lblDate.Text = picList[i].Date.ToShortDateString();
index++;
if (index >= picList.Count) index = 0;
Error : Error 1 Use of unassigned local variable 'i'
VulpesPosted Aug 15, 2014, 8:30 AM
private List
I'm writing this stuff off the top of my head and so mistakes, unfortunately, are inevitable.
ghasem dehPosted Aug 15, 2014, 8:02 AM
private List<picData> picList;
Error :
Error 1 The type or namespace name 'picData' could not be found (are you missing a using directive or an assembly reference?)
VulpesPosted Aug 15, 2014, 6:40 AM
using System.Drawing;
ghasem dehPosted Aug 15, 2014, 5:48 AM
public string Sub {get; set;}
public DateTime Date {get; set;}
public PicData(Image pic, string sub, DateTime date)
{
Pic = pic;
Sub = sub;
Date = date;
}
Error :
Error 1 The type or namespace name 'Image' could not be found (are you missing a using directive or an assembly reference?)
VulpesPosted Aug 15, 2014, 5:30 AM
class PicData
{
public Image Pic {get; set;}
public string Sub {get; set;}
public DateTime Date {get; set;}
public PicData(Image pic, string sub, DateTime date)
{
Pic = pic;
Sub = sub;
Date = date;
}
}
If the image is now a BLOB rather than an Ole Object in the Access database, the code in your form class will be along the following lines:
private int index = 0;
private List<PicData> picList; // EDITED
private void Form1_Load(object sender, EventArgs e)
{
var picList = new List
string conString = "whatever";
var con = new OleDbConnection(conString);
string cmdString = "SELECT pic, sub, date FROM sometable";
con.Open();
var cmd = new OleDbCommand(cmdString, con);
var reader = cmd.ExecuteReader();
while(reader.Read())
{
byte[] bytes = (byte[])reader["pic"];
var ms = new System.IO.MemoryStream(bytes);
Image pic = Image.FromStream(ms);
string sub = reader["sub"].ToString();
DateTime date = Convert.ToDateTime(reader["date"].ToString());
var picData = new PicData(pic, sub, date);
picList.Add(picData);
}
reader.Close();
con.Close();
btnNext.PerformClick(); // load first image
}
private void btnNext_Click(object sender, EventArgs e) // EDITED
{
pictureBox1.Image = picList[index].Pic; // EDITED
lblSub.Text = picList[index].Sub; // EDITED
lblDate.Text = picList[index].Date.ToShortDateString(); // EDITED
index++;
if (index >= picList.Count) index = 0;
}
ghasem dehPosted Aug 15, 2014, 3:44 AM
Guest UserPosted Aug 14, 2014, 8:10 PM