How to Convert the value in DataTable into a string array in c#

前端 未结 6 1194
灰色年华
灰色年华 2020-12-16 00:26

I have a DataTable that contains a single row. I want to convert this DataTable values into a string array such that i can access the column values of that DataTable through

6条回答
  •  臣服心动
    2020-12-16 01:01

     
                string[] result = new string[table.Columns.Count];
                DataRow dr = table.Rows[0];
                for (int i = 0; i < dr.ItemArray.Length; i++)
                {
                    result[i] = dr[i].ToString();
                }
                foreach (string str in result)
                    Console.WriteLine(str);
    

提交回复
热议问题