Skip to content

Remove data into a datagridview

toanhoi bui

Asked Feb 21, 2011, 4:45 AM ESTSolved
Share
LinkedInX
 Hello, everybody .I have a question about database.Can you help me ,please.I have a datagridview which contain three cell are Name,ID,Time
Name | ID   | Time
Toan | 123 | 7:00:01
Tien  | 122 | 7:00:02
Tuan |124  |7:00:03
Toan |123  |7:00:05
Tuan |124  |7:00:07
  I want to use C# and Sql to remove the first row Toan | 123 | 7:00:01 and Tuan |124  |7:00:07 because two rows have same data and if Name is same ,I will delete a row which has old time (Toan | 123 | 7:00:01
 and Toan | 123 | 7:00:05 the program will delete Toan | 123 | 7:00:01
)
After ,I will have a datagridview :
Name | ID   | Time
Tien  | 122 | 7:00:02
Toan |123  |7:00:05
Tuan |124  |7:00:07

 I am using C# to program but I don't write this code.Can you help me,please.Thanks you very much


2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mahesh Chand
    ✓ Accepted answer0
    You actually don't delete data from the DataGridView control. You need to delete data from the data source (DataSet or DataTable) you are using to bring data from the database and store in the application.

    You can remove a row from a DataSet or a DataTable by using DataTable.Rows[RowIndex].Delete() method. For example,

    dataSet1.Tables["Customers"].Rows[0].Delete();

    After that, you call

    dataSet1.Tables["Customers"].AcceptChanges();

    Then you bind dataSet1 to the DataGridView control.
    0
  • 0
    Thanks you very much .But I want to delete name from this table with condition old time.Can you process this  condition in code ?
    0