private SQLiteConnection m;
private SQLiteConnection m1;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string dbPath = @"D:\历年高考分数.db";
string sq = @"Data Source=" + dbPath;
m = new SQLiteConnection(sq);
m.Open();
SQLiteDataAdapter mAdapter = new SQLiteDataAdapter("select province from combox1值", m);
DataSet ds = new DataSet();
mAdapter.Fill(ds);
DataTable dt = ds.Tables[0];
comboBox1.DataSource = dt;
comboBox1.ValueMember = "province";
comboBox1.SelectedIndex = 0;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string dbPath1 = @"D:\历年高考分数.db";
string sq1 = @"Data Source=" + dbPath1;
m1 = new SQLiteConnection(sq1);
m1.Open();
SQLiteDataAdapter mAdapter1 = new SQLiteDataAdapter("select from combox2值", m1);
DataSet ds1 = new DataSet();
mAdapter1.Fill(ds1);
DataTable dt1 = ds1.Tables[0];
comboBox2.DataSource = dt1;
//comboBox2.ValueMember = "province";
comboBox2.SelectedIndex = 0;
//comboBox3.DisplayMember = "列标题";
// m1.Close();
if (comboBox1.SelectedIndex == 0)
{
comboBox2.Items.Clear();
comboBox2.ValueMember = "四川";
}
else if (comboBox1.SelectedIndex == 1)
{
comboBox2.Items.Clear();
comboBox2.ValueMember = "江苏";
}
else if (comboBox1.SelectedIndex == 2)
{
comboBox2.Items.Clear();
comboBox2.ValueMember = "广州";
}
else if (comboBox1.SelectedIndex == 3)
{
comboBox2.Items.Clear();
comboBox2.ValueMember = "直辖市";
}
m1.Close();
}

二个combox 联动(combox都是连接数据库添加值的),逻辑问题,求各位大神帮帮忙
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- threenewbee 2019-07-17 13:02关注
SQLiteDataAdapter mAdapter1 = new SQLiteDataAdapter("select from combox2值", m1);
->
SQLiteDataAdapter mAdapter1 = new SQLiteDataAdapter("select 这里写字段名 from combox2值", m1);本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报