using System.Data.OleDb;
namespace ConnectingToMS_Access1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbDataAdapter da;
DataSet ds;
private void Form1_Load(object sender, EventArgs e)
{
da = new OleDbDataAdapter("Select * from Record", "Provider=Microsoft.Ace.oledb.12.0;data source='D:\\mydb.accdb'");
ds = new DataSet();
da.Fill(ds);
}
private void button1_Click(object sender, EventArgs e)
{
dataGridView1.DataSource = ds.Tables[0];
}
private void button2_Click(object sender, EventArgs e)
{
DataRow dr = ds.Tables[0].NewRow();
dr[0] = "abc";
dr[1] = "def";
dr[2] = "ghi";
dr[3] = "jkl";
ds.Tables[0].Rows.Add(dr);
}
private void button3_Click(object sender, EventArgs e)
{
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
da.Update(ds.Tables[0]);
MessageBox.Show("Saved in Database");
}
}
}
问问题
769 次