Click here to Skip to main content
12,502,578 members (52,802 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET SQL-Server , +
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 22-Nov-12 23:33pm
Updated 22-Nov-12 23:35pm
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 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 | Mobile
Web02 | 2.8.160919.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2016
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