views:

113

answers:

1

I have a page and it lists bunch of tables in a drop down list. I need to load up a list of columns in the database dynamically. In Subsonic 2.0 it could have been done by Subsonic.Schema.BuildTableSchema but not sure how to do it in 3.0. I tried using the code below but does not work ..

SubSonic.Schema.DatabaseTable D = new SubSonic.Schema.DatabaseTable("Users",    
        SubSonic.DataProviders.ProviderFactory.GetProvider("ApplicationConnectionString"));

    foreach (SubSonic.Schema.IColumn Column in D.Columns)
    {
      ListItem Item = new ListItem();

      if ((Column.Name ?? "").IndexOf("Email") != -1)
      {
        Item.Selected = true;
      }

      ddlEmailColumn.Items.Add(Item);
      ddlEmailColumn.SelectedValue = Column.Name;
    }
A: 

I dont think anyone is going to reply to this, so I did it the hard way using the following following sql queries:

SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME = 'Table_Name'

SELECT [name] FROM syscolumns WHERE [id] IN (SELECT [id] FROM sysobjects WHERE [name] = 'Table_Name') AND colid IN (SELECT SIK.colid FROM sysindexkeys SIK JOIN sysobjects SO ON SIK.[id] = SO.[id] WHERE SIK.indid = 1 AND SO.[name] = 'Table_Name')

Peace!!

Deepak Sharma