Using SqlConnection GetSchema in asp.net C#
Add
using System.Data.SqlClient;
Every Database has set of Schema objects associated with it. Using SQL Server Management Studio , user can query all types of objects such as Users in the DB, Databases,Tables,Columns Associated with Each table/view,set of functions and stored procedures etc.,
Programmatically user wants to query Schema Objects , here is the Procedure.
Add Sql Connection Object , which as Instance name and credentials. (By default it will take master database)
SqlConnection conn = new SqlConnection(@"Data Source=localhost\sqlexpress2012;trusted_connection=yes;");
conn.Open();
DataTable schemaTable = conn.GetSchema();
GridView1.DataSource = schemaTable;
GridView1.DataBind();
conn.Open();
DataTable schemaTable = conn.GetSchema();
GridView1.DataSource = schemaTable;
GridView1.DataBind();
>Add GridView to aspx page.
<asp:GridView Font-Names="'Times New Roman',roman"
Caption="<h3 STYLE='BACKGROUND:TEAL;COLOR:WHITE'>Using SqlConnection GetSchema in ASP.NET</H3>"
ID="GridView1" runat="server" Height="179px" Width="652px">
<HeaderStyle BackColor="Teal" ForeColor="WhiteSmoke" />
</asp:GridView>
Caption="<h3 STYLE='BACKGROUND:TEAL;COLOR:WHITE'>Using SqlConnection GetSchema in ASP.NET</H3>"
ID="GridView1" runat="server" Height="179px" Width="652px">
<HeaderStyle BackColor="Teal" ForeColor="WhiteSmoke" />
</asp:GridView>
> Bind to GridView.
| CollectionName | NumberOfRestrictions | NumberOfIdentifierParts |
|---|---|---|
| MetaDataCollections | 0 | 0 |
| DataSourceInformation | 0 | 0 |
| DataTypes | 0 | 0 |
| Restrictions | 0 | 0 |
| ReservedWords | 0 | 0 |
| Users | 1 | 1 |
| Databases | 1 | 1 |
| Tables | 4 | 3 |
| Columns | 4 | 4 |
| AllColumns | 4 | 4 |
| ColumnSetColumns | 3 | 3 |
| StructuredTypeMembers | 4 | 4 |
| Views | 3 | 3 |
| ViewColumns | 4 | 4 |
| ProcedureParameters | 4 | 1 |
| Procedures | 4 | 3 |
| ForeignKeys | 4 | 3 |
| IndexColumns | 5 | 4 |
| Indexes | 4 | 3 |
| UserDefinedTypes | 2 | 1 |
Tags:Using SqlConnection GetSchema in asp.net C#,Get Schema Objects in Sql Server, Get all Schema Objects in SQL Server Database,Get Schema Objects like Databases,tables,Views,Stored procedures,Functions etc.,
No comments:
Post a Comment