2 개의 콤보 상자 및 데이터 표보기가 있습니다. 두 콤보 상자를 별도로 표로 필터링 할 수 있지만 첫 번째 콤보 상자를 기준으로 필터링하려고합니다. 다른 방법을 시도했지만 두 번째 콤보 상자가 비어 있습니다. 아무 일도 일어나지 않습니다. 제발 도와주세요.다른 콤보 상자를 기반으로 C에서 동일한 테이블 데이터를 기반으로 필터링 #
{
String Query = " SELECT distinct [t_street_name] FROM [ICPS].[dbo].[tickets] ";
SqlConnection conDataBase = new SqlConnection(conString);
SqlCommand cmdDataBase = new SqlCommand(Query, conDataBase);
SqlDataAdapter sda = new SqlDataAdapter(cmdDataBase);
SqlDataReader myReader;
try
{
conDataBase.Open();
myReader = cmdDataBase.ExecuteReader();
while (myReader.Read())
{
string t_street_name = myReader["t_street_name"].ToString();
comboBox1.Items.Add(t_street_name);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
void fillcombo1()
{
String Query = ("SELECT distinct [t_zone_name] FROM [ICPS].[dbo].[tickets] where [t_street_name] ='" + comboBox1.SelectedItem + "'conString ") ;
SqlConnection conDataBase = new SqlConnection(conString);
SqlCommand cmdDataBase = new SqlCommand(Query, conDataBase);
SqlDataReader myReader;
try
{
conDataBase.Open();
myReader = cmdDataBase.ExecuteReader();
while (myReader.Read())
{
string t_zone_name = myReader["t_zone_name"].ToString();
comboBox2.Items.Add(t_zone_name);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection conDatabase = new SqlConnection(constring);
conDatabase.Open();
DataTable db = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(String.Format("select distinct * from" + " [ICPS].[dbo].[tickets] " +
"where [ICPS].[dbo].[tickets].[t_street_name] = '" + comboBox1.Text + "'" +
"and ([ICPS].[dbo].[tickets].[t_date_time_issued]) BETWEEN Convert(DATETIME, '{0}', 103) AND Convert(DATETIME, '{1}', 103)", StartDate.Value.ToString("dd/MM/yyyy"), EndDate.Value.ToString("dd/MM/yyyy")), constring);
sda.Fill(db);
dataGridView1.DataSource = db;
}
먼저 매개 변수가있는 쿼리를 사용하십시오. 둘째, 식탁에 대한 자세한 내용을 말해 줄 수 있겠 니? 도움을 드리고 싶지만, 성취하고자하는 바를 구체적으로 이해하지 못합니다. 세부 사항이 많을수록 좋습니다. –
fillcombo1 메서드가 comboBox2에 항목을 추가하는 이유는 무엇입니까? – HadleyHope