コード例 #1
0
        private async void button7_Click(object sender, EventArgs e)
        {
            bool       data_is_true = false;
            SqlCommand SqlCom       = new SqlCommand();

            if (!string.IsNullOrEmpty(textBox11.Text) && Int32.TryParse(textBox11.Text, out int id_for_bd))
            {
                SqlCom = new SqlCommand("SELECT * FROM [Cars] WHERE [Id]=@Id", SqlCon);
                SqlCom.Parameters.AddWithValue("Id", id_for_bd);
                data_is_true = true;
            }
            else if (!string.IsNullOrEmpty(textBox12.Text) && data_is_true == false)
            {
                SqlCom = new SqlCommand("SELECT * FROM [Cars] WHERE [car_name]=@car_name", SqlCon);
                SqlCom.Parameters.AddWithValue("car_name", textBox12.Text);
                data_is_true = true;
            }

            if (data_is_true)
            {
                SqlDataReader SqlReader = null;
                try
                {
                    SqlReader = await SqlCom.ExecuteReaderAsync(); //Сбор данных с таблиц исходы из запроса SqlCom

                    while (await SqlReader.ReadAsync())
                    {
                        listBox3.Items.Clear();
                        listBox3.Items.Add("Найдено:");
                        listBox3.Items.Add(Convert.ToString(SqlReader["Id"]) + "  " + Convert.ToString(SqlReader["car_name"]));
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                finally
                {
                    if (SqlReader != null)
                    {
                        SqlReader.Close();
                    }
                }
            }
            else
            {
                MessageBox.Show("Введите данные", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        private async void button8_Click(object sender, EventArgs e)
        {
            bool       data_is_true = false;
            SqlCommand SqlCom       = new SqlCommand();

            if (!string.IsNullOrEmpty(comboBox3.Text) && Int32.TryParse(textBox4.Text, out int id_for_bd))
            {
                SqlCom = new SqlCommand("SELECT * FROM [" + ChooseDetail(comboBox3.Text) + "] WHERE [Id]=@Id", SqlCon);
                SqlCom.Parameters.AddWithValue("Id", id_for_bd);
                data_is_true = true;
            }

            if (data_is_true)
            {
                SqlDataReader SqlReader = null;
                try
                {
                    SqlReader = await SqlCom.ExecuteReaderAsync(); //Сбор данных с таблиц исходы из запроса SqlCom

                    while (await SqlReader.ReadAsync())
                    {
                        listBox6.Items.Clear();
                        listBox6.Items.Add("Найдено:");
                        listBox6.Items.Add("ID: " + Convert.ToString(SqlReader["Id"]));
                        listBox6.Items.Add("Деталь: " + comboBox3.Text);
                        listBox6.Items.Add("Для машины: " + Convert.ToString(SqlReader["vihicle"]));
                        listBox6.Items.Add("Стоимость: " + Convert.ToString(SqlReader["cost"]));
                        listBox6.Items.Add("Марка: " + Convert.ToString(SqlReader["brand"]));
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    if (SqlReader != null)
                    {
                        SqlReader.Close();
                    }
                }
            }
            else
            {
                MessageBox.Show("Введите данные", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }