Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 23-Nov-12 0:33am
Edited 23-Nov-12 0:35am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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);
  Permalink  
Comments
Dominic Abraham at 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 at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 215
1 Suvendu Shekhar Giri 215
2 Andy Lanng 210
3 PIEBALDconsult 190
4 Abhinav S 184
0 Sergey Alexandrovich Kryukov 6,360
1 OriginalGriff 5,878
2 Peter Leow 2,514
3 Maciej Los 2,263
4 Abhinav S 2,249


Advertise | Privacy | Mobile
Web04 | 2.8.150414.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100