C# 选择要在DataGridView上显示的其他数据库表

C# 选择要在DataGridView上显示的其他数据库表,c#,mysql,database,winforms,datagridview,C#,Mysql,Database,Winforms,Datagridview,我想在datagridview中显示许多数据表 我使用combobox选择其他表,但它无法读取和显示表,因此我将combobox设置为其第一个表,但每次刷新表时,它总是返回到我设置的表 private void UpdateDataGrid() { using (IDbConnection dbconnection = new SQLiteConnection(conn)) { dbconnection.Open();

我想在datagridview中显示许多数据表

我使用combobox选择其他表,但它无法读取和显示表,因此我将combobox设置为其第一个表,但每次刷新表时,它总是返回到我设置的表

 private void UpdateDataGrid()
    {
        using (IDbConnection dbconnection = new SQLiteConnection(conn))
        {
            dbconnection.Open();

           //the other tables are Electrical and Tools
            cbTable.Text = "Plumbing";
            SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter("SELECT * FROM  " + cbTable.Text + "", conn);
            ds = new System.Data.DataSet();

            dataAdapter.Fill(ds, "Item_InFo");
            dgvItems.DataSource = ds.Tables[0];
        }
    }

你从哪里打电话给UpdateDataGrid?您是否使用了IsPostBack?R u使用数据网您在哪里设置cbTable.Text?因为它在您显示的代码中是静态的。如果您使用数据集。您可以将它们存储在dictorial中,同时从组合框中选择每个值,检查dictorial中是否有值id,如果是,则加载该数据表如何设置初始表?是否先设置cbTable.Text,然后调用UpdateDataGrid方法?或者是通过绑定完成的?