C# DataTable转换为一维字符串数组

C# DataTable转换为一维字符串数组

       
        public static string[] dtToArr1(DataTable dt)
        {
            if (dt == null || dt.Rows.Count == 0)
            {
                return new string[0];
            }
            else
            {
                string[] sr = new string[dt.Rows.Count];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (Convert.IsDBNull(dt.Rows[i][8]))
                    {
                        sr[i] = "";
                    }
                    else
                    {
                        sr[i] = dt.Rows[i][8] + "";
                    }
                }
                return sr;
            }
        }
        

你可能感兴趣的:(C#)