Write an Article Write a Tutorial Add a Fast Code* *Fast Code might be any helpful code with brief comment
Stem Cells Blood Banks Insurances .Net Hosting Credit Cards PC Rental Business
Tutorials: ASP .NET C# .NET VB .NET Articles: ASP .NET C# .NET VB .NET Fast Code: ASP .NET C# .NET VB .NET
This Fast Code is a Method which returns a DataTable filled with names of the "User created Tables" for a given Database.
protected DataTable SelectCmd() { string myConnStr = ConfigurationManager.ConnectionStrings["Personal"].ConnectionString; string qurey = @"SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA ='dbo'"; try { using (SqlConnection connection = new SqlConnection(myConnStr)) { using (SqlCommand command = new SqlCommand(qurey, connection)) { command.CommandType = CommandType.Text; connection.Open(); SqlDataReader reader = command.ExecuteReader(); DataTable myTable = new DataTable("myTable"); myTable.Load(reader); return myTable; } } } catch (Exception exp) { msg.Text = "Error Message:" + exp.Message; return null; } }
Protected Function SelectTableObjectsCmd() As DataTable Dim myConnStr As String = ConfigurationManager.ConnectionStrings("ConectionStringNameHere").ConnectionString Dim qurey As String = "SELECT [name] FROM sysobjects WHERE [type] = 'U' AND OBJECTPROPERTY(id, 'IsUserTable') = 1" Try Using connection As New SqlConnection(myConnStr) Using command As New SqlCommand(qurey, connection) command.CommandType = CommandType.Text connection.Open() Dim reader As SqlDataReader = command.ExecuteReader() Dim myTable As New DataTable("myTable") myTable.Load(reader) Return myTable End Using End Using Catch exp As Exception Response.Write("Error Message:" + exp.Message) Return Nothing End Try End Function
@@ Omer Kamal is a Software Developer at Elanize KG Germany. He MSc. Mathematics from Islamia University Bahawalpur, Pakistan and Certified Developer from National Institute of Electronics Islamabad, Pakistan. He is Founder of FriendsPoint.de and Dotnet-Friends.com. He is currently Involved with Microsoft Office SharePoint 2007, Microsoft Dynamics CRM, BI Portal Solutions (Microsoft Dynamics Customization) and Web Security Solutions. Check Omer Kamal Profile
11/06/2008 02:49:21 UTC
02/08/2008 10:00:13 UTC