我的Excel是:我在Excel中2個colums但我想導入某些部分以C#程序
region city iç anadolu ankara iç anadolu ankara iç anadolu ankara iç anadolu ankara iç anadolu kayseri marmara istanbul marmara istanbul marmara istanbul marmara bursa marmara bursa
我想的是,當combobox1選擇iç anadolu
,只有ankara
和kayseri
都出現在combobox2和當在組合框1中選擇marmara
時,組合框2中僅出現istanbul
和bursa
。
我該怎麼做?
這是我的代碼:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
namespace trfd
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection baglan = new OleDbConnection(@"Provider =Microsoft.ACE.OLEDB.12.0;Data Source=C:\\users\\toshiba\\desktop\\proje_ofy\\proje-1; Extended Properties='Excel 12.0 xml;HDR=YES;'");
private void Form1_Load(object sender, EventArgs e)
{
baglan.Open();
string sql = "SELECT * FROM [Sheet1$A1:A100]";
OleDbCommand komut = new OleDbCommand(sql, baglan);
OleDbDataReader dr = null;
dr = komut.ExecuteReader();
while (dr.Read()) {
if (!comboBox1.Items.Contains(dr[0].ToString()))
{
comboBox1.Items.Add(dr[0].ToString());
}
}
}
private void button1_Click(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
}
}}
您所提供的代碼無關和你的 問題(除了在加載時填充組合框),你有什麼嘗試? – Sayse
button1是不必要的。我知道我們在combobox1_selected.ndexcanged中寫了一些東西。但我不知道我寫什麼來完成我的要求。所以他們是空的。 –