Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

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

$
0
0

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 --

privatevoid 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[i];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/

 


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>