SQL Server Column Etiketli Yazılar

C# – SQL Server Column listesini Datatable olarak alma

    

 
public static DataTable GetDatabaseTableColumns(string sConnection, string sDatabase, string sTableName)
        {
            SqlConnection connection = null;
            DataTable dt = null;

            try
            {
                connection = GetConnection(sConnection, sDatabase);
                if (connection == null)
                    return dt;

                SqlParameter[] sqlParms = new SqlParameter[] { new SqlParameter("@table_name", sTableName) };
                DataSet dset = SqlHelper.ExecuteDataset(connection, "sp_columns", sqlParms);

                if ((dset != null) && (dset.Tables.Count > 0))
                    dt = dset.Tables[0];
            }
            catch (Exception ex)
            {
                throw new Exception("GetDatabaseTableColumns error: " + ex.Message);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                    connection.Dispose();
                }
            }

            return dt;
        }