无法从SQL数据库中检索数据

时间:2016-01-06 12:49:31

标签: c# sql sqlconnection

我有一个程序可以将文本框中的一些值插入到数据库中。问题是这些值已成功存储到db中,但我无法将它们存入我的数据网格视图......这里是代码:

    public void LoadMuzee(DataGridView table)
    {
        SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;" + "Initial Catalog=lista_muzee;Integrated Security=SSPI;");
        SqlCommand cmd = new SqlCommand("SELECT muzee.*, gen.gen_nume " +
                                        "FROM muzee INNER JOIN gen " +
                                        "ON muzee.muz_gen_id = gen.gen_id", conn);
        SqlDataAdapter sa = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        conn.Open();
        sa.Fill(dt);
        conn.Close();
        sa.Dispose();
        cmd.Dispose();
        conn.Dispose();
        table.DataSource = dt;
        table.Columns["muz_id"].Visible = false;
        table.Columns["muz_gen_id"].Visible = false;
    }
    public frmMuzee()
    {
        InitializeComponent();
        LoadMuzee(dgvMuzee);
    }

1 个答案:

答案 0 :(得分:0)

您未在gridview上执行数据绑定导致数据未绑定到gridview

table.databind()