Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,167 questions

40,724 answers

573 users

How to safely create and dispose a DataTable in C#

1 Answer

0 votes
using System;
using System.Data;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main()
        {
            using (DataTable table = new DataTable())
            {
                table.Columns.Add("ID", typeof(int));
                table.Columns.Add("Name", typeof(string));
                table.Columns.Add("Salary", typeof(double));

                table.Rows.Add(123, "Ajax", 23492);
                table.Rows.Add(543, "Arrow", 31871);
                table.Rows.Add(876, "Axel", 16878);
                table.Rows.Add(342, "Everly", 46123);

                foreach (DataRow dataRow in table.Rows)
                {
                    foreach (var item in dataRow.ItemArray)
                    {
                        Console.Write("{0} ", item);
                    }
                    Console.WriteLine();
                }
            }
        }
    }
}


/*
run:
   
123 Ajax 23492
543 Arrow 31871
876 Axel 16878
342 Everly 46123
 
*/

 





answered Aug 24, 2018 by avibootz

Related questions

1 answer 189 views
1 answer 31 views
31 views asked Jul 30, 2023 by avibootz
1 answer 32 views
32 views asked Jul 30, 2023 by avibootz
1 answer 90 views
1 answer 84 views
...