Philip

Philip

  • NA
  • 1
  • 0

Viewing Rows in MySQL Table

Mar 8 2008 9:00 AM

 Hi all,

First of all apologies for this real nooby question.

I'm developing a winform app that talks to a MySQL DB using odbc. All works ok but I cannot for the life of me figure out how to loop through the rows in my table.

The following code works but I can only see one row in my table and I know that there are over 30 rows. You will see that I have a commented out a Show method from the MessageBox class which displays the number of rows (yes it displays it 30 times - this was only a test). What I want is for the user to click the button and then all textbox controls to display the data from the next row. Any ideas would be much appreciated and thank you for reading.

 

 

ViewerStr = "SELECT * FROM lead WHERE lead.leadtype LIKE '" + MyODBC.LeadType + "' and lead.leadstate LIKE '3' and lead.counter LIKE '" + MyODBC.Counter + "'";

adapter = new OdbcDataAdapter(ViewerStr, connection);

 

ds = new DataSet();

// Fill the adapter object

adapter.Fill(ds, "lead");

DataTable lead = ds.Tables["lead"];

dv = new DataView(lead);

 

foreach (DataRow row in dv.Table.Rows)

{

try

{

// This is just a test

// MessageBox.Show(row.ToString());

 

string convert;

dateLabel.Text = string.Empty;

convert = dv[0]["leaddate"].ToString();

dateLabel.Text = convert;

site.Text = "This lead was generated on " + dv[0]["website"];

companyName.Text = (string)dv[0]["customername"];

email.Text = (string)dv[0]["customeremail"];

telNumber.Text = (string)dv[0]["customertel"];

contact.Text = (string)dv[0]["contactname"];

intMachine.Text = (string)dv[0]["machinename"];

message.Text = (string)dv[0]["message"];

}

catch (Exception)

{

site.Text = "You have no leads marked as read";

site.ForeColor = Color.Red;

}


Answers (1)