void loadInfo() { string query = ""; if (cityComboBox.Text == "") { query = "SELECT [EventName], [MarathonName], [StartDateTime], [Cost] FROM [Event] join [EventType] on [Event].[EventTypeId] = [EventType].[EventTypeId] join [Marathon] on [Event].[MarathonId] = [Marathon].[MarathonId] where convert(date,[StartDateTime]) = convert(date, '" + dateTimePicker1.Text + "')"; } else if (checkBox1.Checked == false) { query = "SELECT [EventName], [MarathonName], [StartDateTime], [Cost] FROM [Event] join [EventType] on [Event].[EventTypeId] = [EventType].[EventTypeId] join [Marathon] on [Event].[MarathonId] = [Marathon].[MarathonId] where [CityName]='" + cityComboBox.Text + "'"; } else if (cityComboBox.Text != "" && checkBox1.Checked == true) { query = "SELECT [EventName], [MarathonName], [StartDateTime], [Cost] FROM [Event] join [EventType] on [Event].[EventTypeId] = [EventType].[EventTypeId] join [Marathon] on [Event].[MarathonId] = [Marathon].[MarathonId] where [CityName]='" + cityComboBox.Text + "' AND convert(date,[StartDateTime]) = convert(date, '" + dateTimePicker1.Text + "')"; } else { MessageBox.Show("Выберите параметр для проверки"); } con.Open(); SqlDataAdapter da = new SqlDataAdapter(query, con); SqlCommandBuilder cb = new SqlCommandBuilder(da); DataTable dt = new DataTable(); DataSet ds = new DataSet(); da.Fill(ds, "Матчи"); TabledataGridView.DataSource = ds.Tables[0]; TabledataGridView.AutoResizeColumns(); con.Close(); TabledataGridView.Columns[0].HeaderText = "Тип матча"; TabledataGridView.Columns[1].HeaderText = "Название игры"; TabledataGridView.Columns[2].HeaderText = "Полная дата"; TabledataGridView.Columns[3].HeaderText = "Цена билета"; TabledataGridView.AutoResizeColumns(); }
/// <summary> /// This method loads the data of the selected table of the /// selected item in TableNameDropDownList in gridview /// </summary> public void displaydataGrid() { TabledataGridView.Visible = true; TabledataGridView.DataSource = DatabaseClass.getTableDatafromTable(TableNameDropDownList.SelectedItem.ToString()); TabledataGridView.DataBind(); }