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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Aug 15, 2014, 9:47 AM EDT
Guest UserRank #259 · 9.8K reputationPosted Aug 14, 2014, 4:10 PM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 15, 2014, 1:30 AM EDT
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;
}
VulpesRank #55 · 29.2K reputationPosted Aug 15, 2014, 2:40 AM EDT
using System.Drawing;
VulpesRank #55 · 29.2K reputationPosted Aug 15, 2014, 4:30 AM EDT
private List
I'm writing this stuff off the top of my head and so mistakes, unfortunately, are inevitable.
VulpesRank #55 · 29.2K reputationPosted Aug 15, 2014, 5:46 AM EDT
The 'i' should be 'index':
VulpesRank #55 · 29.2K reputationPosted Aug 15, 2014, 7:03 AM EDT
var picList = new List
should be:
The warning should now go away.
VulpesRank #55 · 29.2K reputationPosted Aug 16, 2014, 2:49 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 26, 2014, 11:26 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 27, 2014, 3:30 PM EDT
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.
VulpesRank #55 · 29.2K reputationPosted Aug 29, 2014, 7:39 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 29, 2014, 8:11 AM EDT
com.Parameters.AddWithValue("a", textBox1.Text);
VulpesRank #55 · 29.2K reputationPosted Aug 29, 2014, 12:19 PM EDT
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:
VulpesRank #55 · 29.2K reputationPosted Aug 30, 2014, 7:34 AM EDT
Try making the highlighted changes:
}
index = 0;
if (picList.Count > 0)
{
Next_Click(null, null);
}
else
{
pictureBox1.Image = null;
}
}
ghasem dehRank #8,160 · 227 reputationPosted Aug 14, 2014, 11:44 PM EDT
ghasem dehRank #8,160 · 227 reputationPosted Aug 15, 2014, 1:48 AM EDT
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?)
ghasem dehRank #8,160 · 227 reputationPosted Aug 15, 2014, 4:02 AM EDT
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?)
ghasem dehRank #8,160 · 227 reputationPosted Aug 15, 2014, 5:25 AM EDT
----------------------------------------
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'
ghasem dehRank #8,160 · 227 reputationPosted Aug 15, 2014, 6:45 AM EDT
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
ghasem dehRank #8,160 · 227 reputationPosted Aug 15, 2014, 7:42 AM EDT
this my project
I'm confused ... please checked !
ghasem dehRank #8,160 · 227 reputationPosted Aug 15, 2014, 8:03 PM EDT
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 dehRank #8,160 · 227 reputationPosted Aug 26, 2014, 7:34 AM EDT
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 !
VulpesRank #55 · 29.2K reputationPosted Aug 26, 2014, 8:21 AM EDT
ghasem dehRank #8,160 · 227 reputationPosted Aug 26, 2014, 9:13 AM EDT
ghasem dehRank #8,160 · 227 reputationPosted Aug 27, 2014, 5:46 AM EDT
how to me learn it ?
ghasem dehRank #8,160 · 227 reputationPosted Aug 29, 2014, 2:23 AM EDT
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 ...
VulpesRank #55 · 29.2K reputationPosted Aug 29, 2014, 6:08 AM EDT
What error are you getting?
ghasem dehRank #8,160 · 227 reputationPosted Aug 29, 2014, 7:07 AM EDT
this ERROR
ghasem dehRank #8,160 · 227 reputationPosted Aug 29, 2014, 8:07 AM EDT
ghasem dehRank #8,160 · 227 reputationPosted Aug 29, 2014, 10:47 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 29, 2014, 10:59 AM EDT
ghasem dehRank #8,160 · 227 reputationPosted Aug 29, 2014, 11:34 AM EDT
ghasem dehRank #8,160 · 227 reputationPosted Aug 29, 2014, 11:23 PM EDT
this code NO error ... But not happen !
VulpesRank #55 · 29.2K reputationPosted Aug 30, 2014, 3:01 AM EDT
Try putting it in textBox1_Leave instead.
ghasem dehRank #8,160 · 227 reputationPosted Aug 30, 2014, 6:12 AM EDT
ghasem dehRank #8,160 · 227 reputationPosted Aug 30, 2014, 10:17 AM EDT