Click here to Skip to main content
13,596,080 members
Rate this:
Please Sign up or sign in to vote.
See more: , +
hello everybody i want to export database table structure to excel using c# in
3 tier architecture in and sqlserver 2008 database in 3....
Posted 22-Nov-12 23:33pm
Updated 22-Nov-12 23:35pm

1 solution

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

Solution 1


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);
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web02-2016 | 2.8.180621.3 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

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