How can I know in C# the list of Tables in database.
The list of columns each tables has with complete specification like column one is Id and it has data type of int(50), etc
How can I know in C# the list of Tables in database.
The list of columns each tables has with complete specification like column one is Id and it has data type of int(50), etc
Use the GetSchema method of the SqlConnection class:
DataTable t = _conn.GetSchema("Tables");
For more info read the MSDN article Retrieving Database Schema Information (ADO.NET). Note that this will get you the results without having to write or directly pass/execute any SQL.
Use the information schem views
http://msdn.microsoft.com/en-us/library/ms186778.aspx
Thy are the "standardized way to look at that and contrary to the sys tables quite guaranteed not to change (while the sys.* tables are an implementation detail).
We have previously used SQL Server Management objects with good success. SMO allows you to interact with the SQL Server quite easily thorugh C#. You just need to reference some DLLs and use the object model provided by them. For example, to list the tables you can use the foreach to iterate over the Database.Tables -property.
Codeproject has an article which goes through the basics: http://www.codeproject.com/KB/database/SMODemo.aspx