OleDbConnection con; OleDbDataAdapter datapp; DataSet ds; OleDbCommandBuilder cmdbul; public Form1() {InitializeComponent();} private void button1_Click(object sender, EventArgs e) { try { cmdbul = new OleDbCommandBuilder(datapp); datapp.Update(ds, "Details"); MessageBox.Show("Values Has been Updated"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void Form1_Load(object sender, EventArgs e) { try { con = new OleDbConnection(); con.ConnectionString = "Your Connection String"; con.Open(); datapp = new OleDbDataAdapter("Your Command for the database", con); ds = new DataSet(); datapp.Fill(ds, "Details"); dataGridView1.DataSource = ds.Tables["Details"]; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
In this code we can update our database at runtime with the help of Datagridview and Dataset.