locked
Running While Statement RRS feed

  • Question

  • User-305388250 posted

    Hi,

    I wanted to ask if anybody knows how i can achieve the following. Basically i want to select from a database data that equals the same as the value from a drop down list.

    So i want the result to be the following:-

    Radiocabs (edinburgh) Ltd - this would be the "company_name" field
    5 Upper Bow - this is the "address field"
    Lancashire - "this is the county"
    0131 225 9000

    Above is the "phone" number

    I have written a while statement trying to achieve the goal but it does not work proeprly. Below is my code, how can i change the code to equal this. I basically want it in the form of 7 labels. 1 showing a separate item from the database..

           OleDbConnection conn;
            OleDbCommand cmd;
            OleDbDataReader myReader;

            string cmdString = "SELECT [company_id], [company_name], [address], [county], [postcode], [no_of_seats], [price_per_mile], [phone] " +
                "FROM tbl_taxicompanies WHERE " + "([county] = [@county])";

            conn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; " + "Data Source=|DataDirectory|test.mdb;" +
                "Persist Security Info=False");
            cmd = new OleDbCommand(cmdString, conn);

            cmd.Parameters.Add("@county", OleDbType.VarChar, 50);
            cmd.Parameters["@county"].Value = DropDownList1.SelectedValue;

            conn.Open();
            myReader = cmd.ExecuteReader();

           
            while (myReader.Read())
            {
                for (int i = 0; i < myReader.FieldCount; i++)
                    Label1.Text += myReader.GetValue(i) + " ";
                Label1.Text += ",";
            }

    // This is showing everything in the one label. How can i do it with 7 labels each showing a specific field from the database..?

    Thanks

    Thursday, March 26, 2009 2:28 PM

Answers

  • User1588207957 posted

    you can create the textbox runtime

    or use  Control.FindControl Method  get the textbox

     i.e, ctrlControl.FindContro("TextBox"+ i ).Text=....

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 26, 2009 2:47 PM

All replies

  • User1588207957 posted

    you can create the textbox runtime

    or use  Control.FindControl Method  get the textbox

     i.e, ctrlControl.FindContro("TextBox"+ i ).Text=....

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 26, 2009 2:47 PM
  • User-305388250 posted

    Hey,

    Thanks for your reply. Would i not be able to have something like this?

            while (myReader.Read())
            {
                for (int i = 0; i < myReader.FieldCount; i++)
                    Label1.Text += myReader.GetValue(i) + " ";
                Label1.Text += ",";
            }

    But have:-

    Label1.Text += myReader["company_name"]

    Label2.Text += myReader["address"] 

    Label3.Text += myReader["phone"] 

    Label4.Text += myReader["postcode"] 

    etc.....

    I want the code  to loop through the database and retrieve the values

    Thursday, March 26, 2009 3:00 PM