How to get the number of columns in DataTable with C#

1 Answer

0 votes
using System;
using System.Data;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main()
        {
            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);

            Console.WriteLine(table.Columns.Count);
        }
    }
}


/*
run:
   
3
 
*/

 



answered Aug 23, 2018 by avibootz

Related questions

1 answer 161 views
1 answer 166 views
1 answer 166 views
1 answer 257 views
1 answer 212 views
1 answer 371 views
1 answer 160 views
...