hi.
I want to modify the record in datagridview, after modifying when I press Modify button it should update to access 2007 database and should display the updated record back to datagridview control.
Db name: stpl
table name: Equipments
My code is:
Try
Mycn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & System.Environment.CurrentDirectory & "\STPL.accdb")
Command = New OleDbCommand("SELECT * FROM Equipments", Mycn)
Mycn.Open()
Dim myDA As New OleDbDataAdapter
myDA = New OleDbDataAdapter(Command)
Dim myDataSet As DataSet
Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(myDA)
myDataSet = New DataSet()
myDA.Fill(myDataSet, "Equipments")
Mycn.Close()
DataGridView1.DataSource = myDataSet.Tables("Equipments").DefaultView
txtMan.Focus()
Mycn = Nothing
Catch ex As Exception
MessageBox.Show("Could not Load the Record")
Mycn.Close()
End Try
But the code is doing nothing when I modify the data, no error and no updation to access db.
Plz help me out.
Loading

Satyapriya NayakRank #47 · 31.5K reputationPosted Jul 27, 2012, 12:44 AM EDT
Try this...
App.xml file
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 Update_delete_datagridview
{
public partial class Form1 : Form
{
OleDbDataAdapter oledbda;
OleDbCommandBuilder olcb;
DataTable dataTable;
BindingSource bindingSource;
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
string str;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "SELECT * FROM student";
oledbda = new OleDbDataAdapter(str, con);
olcb = new OleDbCommandBuilder(oledbda);
dataTable = new DataTable();
oledbda.Fill(dataTable);
con.Close();
bindingSource = new BindingSource();
bindingSource.DataSource = dataTable;
dataGridView1.DataSource = bindingSource;
dataGridView1.Columns[0].Visible = false;
}
private void btnaddupdate_Click(object sender, EventArgs e)
{
try
{
oledbda.Update(dataTable);
}
catch (Exception exceptionObj)
{
MessageBox.Show(exceptionObj.Message.ToString());
}
MessageBox.Show("Records updated");
}
private void btndelete_Click(object sender, EventArgs e)
{
try
{
dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);
oledbda.Update(dataTable);
}
catch (Exception exceptionObj)
{
MessageBox.Show(exceptionObj.Message.ToString());
}
MessageBox.Show("Records Deleted");
}
}
}
Thanks
mash alyy12 reputationPosted Jul 27, 2012, 1:02 AM EDT
But I want to edit the record and update it to the acess db 2007 through datagridview only.
I mean: clicking in the datagridview and modifying the record and then pressing modify button to update in the access db 2007 and displaying the updated record in the datagridview using VB.net.