Faixan

Faixan


  • Name: [not set]
  • Favorite Languages: [not set]
  • Website: [not set]
  • Location: [not set]
  • About Me: [not set]

Recent Comments

  • C# Tutorial - Binding a DataGridView to a Database
    07/17/2010 - 03:42

    i tried it on access database

    dAdapter.DeleteCommand = cBuilder.GetDeleteCommand();

    but it doesn't delete record from databse

  • C# Tutorial - Binding a DataGridView to a Database
    07/17/2010 - 03:29

    note: i have used visual Data Grid view so lines related to dataGridView are commented

  • C# Tutorial - Binding a DataGridView to a Database
    07/17/2010 - 03:28

    Here is working class with fewer modifications..

    public partial class Form1 : Form
    {
    private OleDbDataAdapter dAdapter;
    private DataTable dTable;

    public Form1()
    {
    InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
    OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Employee.mdb");
    conn.Open();
    String query = "SELECT * FROM tblEmployee";

    //create an OleDbDataAdapter to execute the query
    dAdapter = new OleDbDataAdapter(query, conn);

    //create a command builder
    OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);

    //create a DataTable to hold the query results
    dTable = new DataTable();

    //fill the DataTable
    dAdapter.Fill(dTable);
    //the DataGridView
    //DataGridView dgView = new DataGridView();

    //BindingSource to sync DataTable and DataGridView
    BindingSource bSource = new BindingSource();

    //set the BindingSource DataSource
    bSource.DataSource = dTable;

    //set the DataGridView DataSource
    dataGridView1.DataSource = bSource;

    dAdapter.Update(dTable);
    }

    // Update button

    private void button1_Click(object sender, EventArgs e)
    {

    dAdapter.Update(dTable);

    }

    }