コード例 #1
0
ファイル: DBexplorerForm.cs プロジェクト: BHovorunets/VLib
        //----------------------------------------------------------------------------------------

        #region Select Function

        private void SelectButton_Click(object sender, EventArgs e)
        {
            if (table != null)
            {
                try
                {
                    StringBuilder command = new StringBuilder(String.Format("WHERE {0} {1} ",
                                                                            filterBox.SelectedItem,
                                                                            compererBox.SelectedItem));

                    if (compererBox.Text == "LIKE" || compererBox.Text == "NOT LIKE")
                    {
                        command.AppendFormat("'%{0}%' ", filterTextBox.Text);
                    }
                    else
                    {
                        command.AppendFormat("'{0}' ", filterTextBox.Text);
                    }


                    for (int i = 0; i < 3; i++)
                    {
                        ComboBox andOrBox = null;
                        if (this.groupBox2.Controls.Find("AddFilterBox" + i, false).Length != 0)
                        {
                            andOrBox = this.groupBox2.Controls.Find("AddFilterBox" + i, false)[0] as ComboBox;

                            command.AppendFormat(" {0} ", andOrBox.Text);

                            if (andOrBox != null && andOrBox.SelectedIndex != -1)
                            {
                                command.AppendFormat("{0} {1} ", this.groupBox2.Controls.Find("FilterBox" + i, false)[0].Text,
                                                     this.groupBox2.Controls.Find("CompererBox" + i, false)[0].Text);

                                if (this.groupBox2.Controls.Find("CompererBox" + i, false)[0].Text == "LIKE" ||
                                    this.groupBox2.Controls.Find("CompererBox" + i, false)[0].Text == "NOT LIKE")
                                {
                                    command.AppendFormat("'%{0}%' ", this.groupBox2.Controls.Find("FilterTextBox" + i, false)[0].Text);
                                }
                                else
                                {
                                    command.AppendFormat("'{0}' ", this.groupBox2.Controls.Find("FilterTextBox" + i, false)[0].Text);
                                }
                            }
                        }
                    }

                    dataGridView1.DataSource = TableExplorer.SelectTable(command.ToString(), "SELECT * FROM " + table.TableName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Some SELECT fields are empty or irregular! \n" + ex.Message);
                }
            }
            else
            {
                MessageBox.Show("There is no table selected!");
            }
        }
コード例 #2
0
        private void ComplexQueryForm_Load(object sender, EventArgs e)
        {
            DataTable table = TableExplorer.SelectTable("", "SELECT DISTINCT m.MovieID, m.Title FROM Movies m RIGHT JOIN MovieActors ma ON m.MovieID = ma.MovieID");

            MoviesComBox.DataSource    = table;
            MoviesComBox.DisplayMember = "Title";
            MoviesComBox.ValueMember   = "MovieID";
        }
コード例 #3
0
 private void MoviesComBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (MoviesComBox.SelectedValue is int)
     {
         string command = String.Format(
             "SELECT X.ActorID, FName, LName, DateOfBirth, CountryOfBirth, CityOfBirth  " +
             "FROM MovieActors X " +
             "JOIN Actors a ON a.ActorID = X.ActorID WHERE MovieID = \'{0}\'", MoviesComBox.SelectedValue);
         dataGridView1.DataSource = TableExplorer.SelectTable("", command);
     }
 }