c#winform单击左边treeview的子项(子项是A这张表的一个字段),然后在右边的datagridview显示查询后的记录
单击左边treeview中的子项(这个子项是A这张表里的一个字段),然后在右边的datagridview显示查询后的记录,子项的这个字段是车牌号码carNum,从tree...
单击左边treeview中的子项(这个子项是A这张表里的一个字段),然后在右边的datagridview显示查询后的记录,子项的这个字段是车牌号码carNum,从treeview取值后,用查询语句来筛选记录显示,为什么现在单击完子项后datagridview不显示筛选后的记录呢,小白恳请大神指教。下面是代码: private void GetData(string selectCommand) { try{MySqlConnection conn = db.Camcon();MySqlDataAdapter dataAdapter = newMySqlDataAdapter(selectCommand, conn);MySqlCommandBuilder commandBuilder = new MySqlCommandBuilder(dataAdapter);DataTable table = new DataTable();table.Locale =System.Globalization.CultureInfo.InvariantCulture;dataAdapter.Fill(table);bindingSource1.DataSource = table; conn.Close(); } catch (MySqlException) {} } private void Tv_CarNum_AfterSelect(object sender, TreeViewEventArgs e){TreeNode node = Tv_CarNum.SelectedNode;if (node.Nodes.Count > 0){dgv_CarDaily.DataSource = bindingSource1;GetData("select * from cardaily"); }else {string key; if (node == null) return;if (node.Level != 1) return;key = node.Text;string selectCommand = "select * from cardaily where carNum = '" + key + "' ";MySqlConnection conn = db.Camcon();MySqlDataAdapter dataAdapter = new MySqlDataAdapter(selectCommand, conn);DataSet ds = new DataSet();dataAdapter.Fill(ds,"cardaily"); this.dgv_CarDaily.DataSource = ds;this.dgv_CarDaily.DataMember = "cardaily";}}
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询