locked
please help me! =( RRS feed

  • Question

  •  hi,im new in c# window form.
    i got problem in deleting record from the datagridview and database ms access.
    can anyone help me on this?cos im terribly stress on this as i've been working on this since last wk..

    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)

    {

    con = new System.Data.OleDb.OleDbConnection();

    con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:/projectDb.mdb";

    con.Open();

    //string sql = "SELECT * FROM Table1 where command = '" + dataGridView1.CurrentRow.Index +"'";

    string sql = "SELECT * FROM Table1 where command = '" + dataGridView1.CurrentCell.RowIndex + "'";

    OleDbCommand command = new OleDbCommand(sql,con);

    OleDbDataReader dr = command.ExecuteReader();

    DataSet dset = new DataSet();

    da = new System.Data.OleDb.OleDbDataAdapter(sql, con);

    DataRow selectedRow = dataTable.Rows[dataGridView1.SelectedRows];

    selectedRow.Delete();

    da.Update(dset, "Table1");

    dset.AcceptChanges();

    // DataGridViewRow row = new DataGridViewRow();

    // dataGridView1.SelectedRows.Contains(row );

    da.Fill(dset, "Table1");

    //dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);

    // if (row.Index != dataGridView1.Rows.Count)

    if (dr.Read())

    {

    textBox4.Text = dr["class"].ToString();

    textBox5.Text = dr["command"].ToString();

    }

    // dataGridView1.DataSource = dset.Tables["Table1"].DefaultView;

    // dataGridView1.DataSource = dr;

    dr.Close();

    con.Close();

    }


    my code is already in a mess.pls do help..

    Wednesday, November 19, 2008 6:52 AM