#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    159
    Rep Power
    31

    Lightbulb C# howto better handle array of data from mysql command


    Code:
                command.CommandText = "SELECT id, name, urgency, lastreply FROM tbltickets WHERE status = 'Open'";
                connection.Open();
                Reader = command.ExecuteReader();
                while (Reader.Read()) {
                    string thisrow = "";
                    for (int i = 0; i < Reader.FieldCount; i++)
                        thisrow += Reader.GetValue(i).ToString() + ",";
                    outputBox.Items.Add(thisrow);
                }
                connection.Close();
    Instead of adding the data to the listbox and referring to the rowdata by 0/1/2/3 how can I pull the data by field name (iid, name, urgency, lastreply)?
    string thisrow = "http://urliwant2go2.com/ticket.php?id="+Reader.GetValue('id').ToString();
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0
    var id = reader["id"];

    is this what u meant?

IMN logo majestic logo threadwatch logo seochat tools logo