MSDN Magazine - October 2008 - (Page 24) The “Web Like Desktop” Revolution Eliminating Web Limitations Figure 2 GetTableSchema CREATE PROCEDURE dbo.GetTableSchema ( @table varchar(50) ) AS SELECT c.table_name As TableName, c.column_name As ColumnName, c.data_type As DataType, c.character_maximum_length As MaxLength, COALESCE ( ( SELECT CASE cu.column_name WHEN null THEN 0 ELSE 1 END FROM information_schema.constraint_column_usage cu INNER join information_schema.table_constraints ct ON ct.constraint_name = cu.constraint_name WHERE ct.constraint_type = 'PRIMARY KEY' AND ct.table_name = c.table_name AND cu.column_name = c.column_name ),0) AS IsPrimaryKey FROM information_schema.columns c INNER JOIN information_schema.tables t ON c.table_name = t.table_name WHERE @table = t.table_name and (t.table_type = 'BASE TABLE' and not (t.table_name = 'dtproperties') and not (t.table_name = 'sysdiagrams')) ORDER BY c.table_name, c.ordinal_position Desktop Simplicity Proven 90% saving in development Desktop Performance Regardless of application's size & weight Flexibility Customizable & extendable Interoperability Integrates with any .NET component Desktop Security No exposure of data, logic & tokens on client DHTML or Silverlight Develop once access either way all ity at last r Goodyea “Simplic ” ASP MVP WOW u uctive yo ow prod hl MVP Stra iculous h ” “It’s rid l like this ith a too can be w . You m. Magic and Boo is a n This ompile it “C pplicatio a web A Saar af have n” SAP As revolutio ven Field Pro I can say is UI should look based on the table’s schema. You can use reflection to look at your object model. But if the model is really simple and maps one-to-one to your database table anyway, you can just ask the database to return the metadata about its tables. In order to generate a simple UI, you would probably want to obtain, at minimum, the following properties for each column in a table: ColumnName, DataType, MaxLength, and IsPrimaryKey. One way to do this is by creating a stored procedure called GetTableSchema (in this example, I’m using the Northwind database) that uses the information schema views to return this basic schema for any given table (see Figure 2). A simple and strongly typed way to access this stored procedure is to add a new LINQ to SQL classes item to your project, expand the Stored Procedures node in the Server Explorer for the dataFigure 3 'H¾QLQJWKH:LQGRZ ID Find Save Free Download Live Demo Visit us at PDC2008 Booth 110 www.VisualWebGui.com 24 msdn magazine Basic Instincts http://www.VisualWebGui.com
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.