Get the column names of a table and store them in a string or var c# asp.net

前端 未结 6 1057
我寻月下人不归
我寻月下人不归 2021-01-03 16:29

I was wondering how I could get the columns of a database table and store each of them in a string or string array. I have the following code but I believe it does not work.

6条回答
  •  有刺的猬
    2021-01-03 17:03

    Very Simply U can do it like below code..

    DataTable table = new DataTable();
    foreach (DataColumn column in table .Columns)
    {
        Console.Write("Item: ");
        Console.Write(column.ColumnName);
        Console.Write(" ");
        Console.WriteLine(row[column]);
    }
    

提交回复
热议问题