How to refresh or show immediately in datagridview after inserting?

后端 未结 8 1127
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 14:32

After entering data into all the textbox, and after clicking the submit button, it won\'t immediately show in the datagridview, I need to reopen the form in order to see the

8条回答
  •  孤城傲影
    2020-11-28 14:52

    You can set the datagridview DataSource to null and rebind it again.

    private void button1_Click(object sender, EventArgs e)
    {
        myAccesscon.ConnectionString = connectionString;
    
        dataGridView.DataSource = null;
        dataGridView.Update();
        dataGridView.Refresh();
        OleDbCommand cmd = new OleDbCommand(sql, myAccesscon);
        myAccesscon.Open();
        cmd.CommandType = CommandType.Text;
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        DataTable bookings = new DataTable();
        da.Fill(bookings);
        dataGridView.DataSource = bookings;
        myAccesscon.Close();
    }
    

提交回复
热议问题