Get column name from SQL Server

后端 未结 7 2251
礼貌的吻别
礼貌的吻别 2021-02-14 05:32

I\'m trying to get the column names of a table I have stored in SQL Server 2008 R2.

I\'ve literally tried everything but I can\'t seem to find how to do this.

Ri

7条回答
  •  爱一瞬间的悲伤
    2021-02-14 06:33

    I typically use the GetSchema method to retrieve Column specific information, this snippet will return the column names in a string List:

            using (SqlConnection conn = new SqlConnection(""))
            {
                string[] restrictions = new string[4] { null, null, "", null };
                conn.Open();
                var columnList = conn.GetSchema("Columns", restrictions).AsEnumerable().Select(s => s.Field("Column_Name")).ToList();
            }
    

提交回复
热议问题