j c

j c

  • NA
  • 45
  • 0

return datatable in gridview

Oct 15 2010 6:10 PM

I am trying to create a class ( method) so i can call it in gridview in asp.net
how can I create a method  returns a datatable  and display in gridview? asp.net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using   Microsoft.AnalysisServices;
 
namespace UserSecurity
{
    public class GetCurrentCubeRoleInfo
    {

        public static void CurrentCubeRoleInformation()
        {
            Server amoServer = new Server();
            Database amoDatabase = new Database();
            Role amoRole = new Role();
            RoleMember amoRoleMember = new RoleMember();
            Cube amoCube = new Cube();
            CubePermission amoCubePermission = new CubePermission();
            CubeDimensionPermissionCollection amoCubeDimensionPermissionCollection = default(CubeDimensionPermissionCollection);
            CubeDimensionPermission amoCubeDimensionPermission = new CubeDimensionPermission();
            DimensionAttribute amoDimensionAttribute = new DimensionAttribute();
            string DimensionReadPermission = null;
            DataTable tblDataTable;

            //create datatable
            tblDataTable = new DataTable("AmoSecurityTable");
            //create attributes for mapping security metadata
            tblDataTable.Columns.Add(new DataColumn("Role", typeof(string)));
            tblDataTable.Columns.Add(new DataColumn("CubeDatabase", typeof(string)));
            tblDataTable.Columns.Add(new DataColumn("Cube", typeof(string)));
            tblDataTable.Columns.Add(new DataColumn("CubeAccessCode", typeof(string)));
            tblDataTable.Columns.Add(new DataColumn("Rolemember", typeof(string)));
            ///''''''''''''''''''''''''''''''
            //Establish a connection to the Analysis Server.
          
            amoServer.Connect("Data Source=test;Initial Catalog=cube1;Provider=MSOLAP.3;Integrated Security=SSPI;Impersonation Level=Impersonate;");
            // amoDatabase = amoServer.Databases.GetByName("cube1");
            amoCube.Name = "testcube";
 

         
            foreach (Database amoDatabase1 in amoServer.Databases)
            {
                {
                    //Create DataRow based on tblDataTable Object
                    DataRow dr = tblDataTable.NewRow();

                    //Assign AMO security values to DataRow attributes
 
                    dr["Role"] = amoRole.Name;
                    dr["CubeDatabase"] = amoDatabase.Name.ToString();
                    dr["Cube"] = amoCube.Name;
                    dr["CubeAccessCode"] = amoCube.CubePermissions.GetByRole(amoRole.ID).Read.ToString();
                    dr["RoleMember"] = amoRoleMember.Name;
                    //Add DataRow row to tblDataTable
                    tblDataTable.Rows.Add(dr);
 

                }

            }

      
        }
    }

                   
             

Answers (3)