Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
hello everybody i want to export database table structure to excel using c# in
3 tier architecture in asp.net and sqlserver 2008 database in 3....
Posted
Updated 22-Nov-12 23:35pm
v2

1 solution

Hi

Can you check the following code:

using System.Data.SqlClient;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;


 SqlConnection conSql = new SqlConnection(ConnectionString);
            ServerConnection con = new ServerConnection(conSql);
            Server server = new Server(con);
            DatabaseCollection dbCollection = server.Databases;
            TableCollection tbls = dbCollection["YOURDBNAME"].Tables;
            System.Collections.Specialized.StringCollection sCollection = tbls["YOURTABLENAME"].Script();
            StringBuilder sb = new StringBuilder();
            string[] tblscriptArray = new string[tbls["YOURTABLENAME"].Script().Count];
            sCollection.CopyTo(tblscriptArray, 0);
 
Share this answer
 
Comments
Dominic Abraham 23-Nov-12 11:37am    
If the solution is helpful don't forget to mark it as answer. So that it may help others.
dhinamit 26-Nov-12 8:19am    
thanks for ur solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900