forum.venkateswarlu.net
      Register      Login
Delete datarow from dataset

3 replies to this topic

Laxman B #1
Member
42 Points
Posted on 22 Sep 2014 01:10 PM IST
static void Main(string[] args)
        {
            DataTable table = GetTable();

            for (int i = 0; i < table.Rows.Count; i++)
            {
                table.Rows[i].Delete();

            }

        }
        static DataTable GetTable()
        {
            //
            // Here we create a DataTable with four columns.
            //
            DataTable table = new DataTable();
            table.Columns.Add("Dosage", typeof(int));
            table.Columns.Add("Drug", typeof(string));
            table.Columns.Add("Patient", typeof(string));
            table.Columns.Add("Date", typeof(DateTime));

            //
            // Here we add five DataRows.
            //
            table.Rows.Add(25, "Indocin", "David", DateTime.Now);
            table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
            table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
            table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
            table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
            return table;
        }
 
C#.NET     836 views     Reply to this topic
Kalyan Suman #2
Member
150 Points
Replied on 28 Oct 2014 03:33 PM IST

As per your question delete record from data table u used for loop thats good

so same depends upon id u can delete

int max = dt.Rows.Count - 1;

for(int i = max; i >= 0; --i)
{
         
if((int)dt.Rows[i].ItemArray[0] == someValue)
        
{
       
         dt.Rows[i].BeginEdit();
       
         dt.Rows[i].Delete();
        }
        else
     
         break;
}

dt.AcceptChanges();

 

 
Reply to this topic
Cherukuri Venkateswarlu #3
Member
140 Points
Replied on 28 Oct 2014 11:12 PM IST Hi Suman,

I appreciate for your reply in our Forum.

Thanks,
Venkat
 
Reply to this topic
Laxman B #4
Member
42 Points
Replied on 11 Jun 2015 02:17 PM IST Tq for the reply 
Reply to this topic