How to Delete selected row in data grid view and database by C#

  • Thread starter Thread starter Exodia
  • Start date Start date
E

Exodia

Guest
[Broken External Image]:http://social.msdn.microsoft.com/Fo...ts and Settings/User/Desktop/Delete Error.jpg I wish to ask how i can delete the both database and selected row from data grid view by using C# windows form button??

This was the code i using --




private void del_list_Click(object sender, EventArgs e)
{
System.Collections.ArrayList alv = new System.Collections.ArrayList();
int i = 0;

OleDbCommand delcmd = new OleDbCommand();

for (i = 0; i < dataGridView1.Rows.Count; i++)
{
DataGridViewRow delrow = dataGridView1.Rows;
if (delrow.Selected == true)
{
dataGridView1.Rows.RemoveAt(i);
try
{
delcmd.CommandText = "DELETE FROM Receive WHERE CustCode=" + i + "";
int count = delcmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}

}
}

}



and getting some kind of error like this--

http://www.mypicx.com/02212011/Error_Msg/

Continue reading...
 
Back
Top