N
N
Nastya06962016-06-07 17:44:58
C++ / C#
Nastya0696, 2016-06-07 17:44:58

How to search two joined tables?

There are two tables that are joined using the query
SELECT disciplina.nazvanie, disciplina.kolvo, disciplina.ekzzach, disciplina.uch, disciplina.spec,
dis.kursovoi From disciplina Inner Join dis On disciplina.nazvanie = dis.nazvanie
you need to do a search on joint table

private void search_nazv()
        {
            try
            {
                if (textBox8.Text != string.Empty)
                {
                    DataSet dataSet = new DataSet();
                    BindingSource binding = new BindingSource();

                    SqlDataAdapter poi = new SqlDataAdapter(@"SELECT  disciplina.nazvanie, disciplina.kolvo, disciplina.ekzzach, disciplina.uch, disciplina.spec, 
    dis.kursovoi From disciplina Inner Join dis On disciplina.nazvanie = dis.nazvanie FROM dis O WHERE  O.nazvanie LIKE N'%" + this.textBox8.Text + "%'", conpoezdb);
                    poi.Fill(dataSet, "dis");
                    binding = new BindingSource(dataSet, "dis");
                    dataGridView2.DataSource = binding;
                }

            }
            catch (SqlException sqlExcept)
            { MessageBox.Show(sqlExcept.Message); }
        }

        private void search_fio()
        {
            try
            {
                if (textBox8.Text != string.Empty)
                {
                    DataSet dataS = new DataSet();
                    BindingSource binding = new BindingSource();

                    SqlDataAdapter poi = new SqlDataAdapter(@"SELECT disciplina.nazvanie, disciplina.kolvo, disciplina.ekzzach, disciplina.uch, disciplina.spec, 
    dis.kursovoi From disciplina Inner Join dis On disciplina.nazvanie = dis.nazvanie FROM disciplina K WHERE K.fio LIKE N'%" + this.textBox8.Text + "%'", conpoezdb);
                    poi.Fill(dataS, "dis");
                    binding = new BindingSource(dataS, "dis");
                    dataGridView2.DataSource = binding;
                }
            }
            catch (SqlException sqlExcept)
            { MessageBox.Show(sqlExcept.Message); }
        }


        private void textBox8_TextChanged(object sender, EventArgs e)
        {
            if (comboBox1.Text == "nazvanie")
            {
                SqlConnection po = new SqlConnection("Data Source=JUSTYX;Initial Catalog=julia;Integrated Security=True");
                SqlDataAdapter sda = new SqlDataAdapter(@"SELECT nazvanie, kolvo, fio, ekzzach, uch, spec, kursovoi FROM dis WHERE nazvanie like '%" + textBox8.Text + "%' ", po);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                dataGridView2.DataSource = dt;
            }
            else if (comboBox1.Text == "fio")
            {
                SqlConnection po = new SqlConnection("Data Source=JUSTYX;Initial Catalog=julia;Integrated Security=True");
                SqlDataAdapter sda = new SqlDataAdapter("SELECT nazvanie, kolvo, fio, ekzzach, uch, spec, kursovoi FROM dis WHERE fio like '%" + textBox8.Text + "%'", po);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                dataGridView2.DataSource = dt;
            }
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MrDywar Pichugin, 2016-06-07
@Dywar

Requests to storages and call them, or use EF.
Two Table Query: Combine Two Tables in Select

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question