delete row from dataGridView problem


A

alexl

Hi All,
I have been failing to delete a row from dataGridView.
I use typed dataset.
Here is my code, please advice what wrong is here?

private void MainForm_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the
'lodgersDataSet1.Table_Lodgers' table. You can move, or remove it, as
needed.


this.table_LodgersTableAdapter1.Fill(this.lodgersDataSet1.Table_Lodgers);



}


private void dataGridViewLodgers_RowsRemoved(object sender,
DataGridViewRowsRemovedEventArgs e)
{
string strConnString = @"Data Source=XP\SQLEXPRESS;Initial
Catalog=Lodgers;Integrated Security=True";
SqlConnection sqlConnection = new SqlConnection(strConnString);
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM
Table_1",sqlConnection);

MyDataSet myDataSet = new MyDataSet();
da.Fill(myDataSet, "Table_1");


// myDataSet is updated, row is deleted properly
//
DataRow dr = myDataSet.Table_1.Rows[e.RowIndex];
myDataSet.Tables["Table_1"].Rows.Remove(dr);


// Update returns 0 !!!
//
int ret = daLodgers.Update(dsLodgers2,
dsLodgers2.Tables[0].TableName);


myDataSet.Table_1.AcceptChanges();
myDataSet.AcceptChanges();



}


Thank you in advance
A.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top