Beispiel #1
0
        protected void Show_All_Click(object sender, EventArgs e)
        {
            int    selectedIndex = SearchDropDown.SelectedIndex;
            String tableName     = "health_profile";

            if (selectedIndex == 1)
            {
                tableName = "diet";
            }
            else if (selectedIndex == 2)
            {
                tableName = "enum_health_condition";
            }
            else if (selectedIndex == 3)
            {
                tableName = "health_profile";
            }
            else if (selectedIndex == 4)
            {
                tableName = "enum_medication";
            }
            else if (selectedIndex == 5)
            {
                tableName = "prescription";
            }
            else if (selectedIndex == 6)
            {
                tableName = "animal";
            }
            using (MySqlConnection conn = new MySqlConnection(CONNECTION_STR))
            {
                try
                {
                    // Connect to Azure MySQL server
                    System.Diagnostics.Debug.WriteLine("Connecting to server...");
                    conn.Open();

                    string       query = "SELECT * FROM " + tableName;
                    MySqlCommand cmd   = new MySqlCommand(query, conn);


                    MySqlDataAdapter adapter = new MySqlDataAdapter();
                    adapter.SelectCommand = cmd;

                    DataTable table = new DataTable();
                    adapter.Fill(table);
                    SearchOutput.DataSource = table;
                    SearchOutput.DataBind();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
                }
            }
        }
Beispiel #2
0
        protected void SearchBtn_Click(object sender, EventArgs e)
        {
            // Get user input
            int    keyID         = Convert.ToInt32(SearchInput.Text.Trim());
            int    selectedIndex = SearchDropDown.SelectedIndex;
            String tableName     = "health_profile";
            String primaryKey    = "profile_id";

            if (selectedIndex == 1)
            {
                tableName  = "diet";
                primaryKey = "diet_id";
            }
            else if (selectedIndex == 2)
            {
                tableName  = "enum_health_condition";
                primaryKey = "condition_id";
            }
            else if (selectedIndex == 3)
            {
                tableName  = "health_profile";
                primaryKey = "profile_id";
            }
            else if (selectedIndex == 4)
            {
                tableName  = "enum_medication";
                primaryKey = "med_id";
            }
            else if (selectedIndex == 5)
            {
                tableName  = "prescription";
                primaryKey = "prescription_id";
            }
            else if (selectedIndex == 6)
            {
                tableName  = "animal";
                primaryKey = "animal_id";
            }
            using (MySqlConnection conn = new MySqlConnection(CONNECTION_STR))
            {
                try
                {
                    // Connect to Azure MySQL server
                    System.Diagnostics.Debug.WriteLine("Connecting to server...");
                    conn.Open();

                    string       query = "SELECT * FROM " + tableName + " WHERE " + primaryKey + " = @key_id;";
                    MySqlCommand cmd   = new MySqlCommand(query, conn);
                    cmd.Parameters.AddWithValue("@key_id", keyID);

                    MySqlDataAdapter adapter = new MySqlDataAdapter();
                    adapter.SelectCommand = cmd;

                    DataTable table = new DataTable();
                    adapter.Fill(table);
                    SearchOutput.DataSource = table;
                    SearchOutput.DataBind();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
                }
            }
        }