Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   Deletimg row from datagridview (http://www.go4expert.com/forums/deletimg-row-datagridview-t27692/)

kermit2012 31Jan2012 03:39

Deletimg row from datagridview
 
Hi,

I have got a delete button on my DataGridView and when I press it, I want it to delete the row selected, I have currently got the code below, but when I press it nothing happens, can anybody tell me why?

thanks

Code:

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
string queryString = "SELECT AccountID, Title, FirstName, LastName, AccountType, Username, UserPass FROM AddAccount";
int currentRow = int.Parse(e.RowIndex.ToString());

{
string movieIDString = dataGridView1[0, currentRow].Value.ToString();
movieIDInt = int.Parse(movieIDString);
}
if (dataGridView1.Columns[e.ColumnIndex] == deleteButton && currentRow >= 0)
{
//delete sql query
string queryDeleteString = "DELETE FROM Account where AccountID = '"+movieIDInt+"'";
OleDbCommand sqlDelete = new OleDbCommand();
sqlDelete.CommandText = queryDeleteString;
sqlDelete.Connection = database;
sqlDelete.ExecuteNonQuery();
loadDataGrid(queryString);
}
}
}
}



All times are GMT +5.5. The time now is 21:55.