以下代码是否能根据combobox中的选择在datagridview中显示相应的数据表信息?

图片说明
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace login
{
public partial class 导出数据表结构 : Form
{
public 导出数据表结构()
{
InitializeComponent();
}

    private void button1_Click(object sender, EventArgs e)
    {
        string command="";
        if (comboBox1.Text == "企业基本信息库")
        {
            command = String.Format("select * from 企业基本信息库");

        }
        else if (comboBox1.Text == "监察员信息") 
        {
            command = String.Format("select * from 监察员信息");
        }
        else if (comboBox1.Text == "企业现场基本情况库")
        {
            command = String.Format("select * from 企业现场基本情况库");
        }
        else if (comboBox1.Text == "每年每组现场监察信息")
        {
            command = String.Format("select * from 每年每组现场监察信息");
        }
        string str = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=qyjc.mdb";
        OleDbConnection con = new OleDbConnection(str);
        con.Open();
        OleDbDataAdapter da = new OleDbDataAdapter(command, con);
        DataSet ds = new DataSet();

        da.Fill(ds);
        this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
        con.Close();
        con.Dispose();
        da.Dispose();
        ds.Dispose();
    }
}

}

看你写代码的思路,应该是对的,哪个地方出错了吗?可以单步调试一下

这个肯定是可以的。当combobox选择的值 改变的时候 你改变表的数据源不就可以了吗