Image from Access database to C# picturebox

I somehow found an easier way. :)

picLaptops.Image = Image.FromFile(ds1.Tables["Laptops"].Rows[inc].ItemArray.GetValue(2).ToString());

I do however have a new question.

The tutorial for finding records at the same site only searches one field and displays one thing in a messagebox.

http://www.homeandlearn.co.uk/csharp/csharp_s12p12.html

I worked out how to display multiple stuff on new lines

MessageBox.Show("Maker - " + (dr1[1].ToString() + "\n" + "Model - " + (dr1[2].ToString() + "\n" + "Current Price - £" + (dr1[3].ToString()))));

How do I search all fields? (eg I will only get a result from typing in the Maker and not price or model number) Relevant code is this.

string searchFor = txtSearch.Text;
returnedRows = ds1.Tables["Laptops"].Select("Maker='" + searchFor + "'");
 
Last edited:
I tried this,

returnedRows = ds1.Tables["Laptops"].Select("Maker='" + "ID='" + searchFor + "'");

Where ID and Maker are rows. It fails. I have tried different combinations of using AND aswell. Nothing works.

*searchFor is equal to a textbox where the user inputs a word to check against database*
 
Last edited:
I got it working. :)

I however have a new issue. I am trying to implement a Skip function on the ID field.

I have this for my skip button.

int id = Int32.Parse(txtSkip.Text);

DataRow row = ds1.Tables["Laptops"].Rows.OfType<DataRow>()
.SingleOrDefault(r => (int)r.ItemArray[0] == id);

processRow(row);

process row is this.

void processRow(DataRow row)
{
txtMaker.Text = row.ItemArray.GetValue(1).ToString();
txtModel.Text = row.ItemArray.GetValue(2).ToString();
txtPrice.Text = row.ItemArray.GetValue(3).ToString();
txtBids.Text = row.ItemArray.GetValue(4).ToString();
txtScreen.Text = row.ItemArray.GetValue(5).ToString();
txtCPU.Text = row.ItemArray.GetValue(6).ToString();
txtMemory.Text = row.ItemArray.GetValue(7).ToString();
txtHD.Text = row.ItemArray.GetValue(8).ToString();
picLaptops.Image = Image.FromFile(row.ItemArray.GetValue(9).ToString());
}

That code will show the information the user enters in the textboxes (from the ID number) but the problem is, it does not update the inc variable which still holds 0 when you clicked the Next Item button. For example, if I type in an ID of 7 (7th in the list) and then click Next, I will be taken to the 2nd item in the list since Next still thinks I am on row 1. How can I make the inc update to what ID I skip to? So that in the example given it would go to record 8 when I click Next?
 
Last edited:
Back
Top Bottom