C # GetSchema Get List of Table acquire all of the database table names and methods record number of pieces of the table

 

Database connection as follows:

<add key="BusinessDbConnection" value="Data Source=localhost;Initial Catalog=PRM;User Id = sa ; Password = "@sa ;" />

 

code show as below:

// --------------------------------------------------------------------
//  All Rights Reserved , Copyright (C) 2011 , Hairihan TECH, Ltd. 
// --------------------------------------------------------------------

using System.Data;
using System.Data.SqlClient;

namespace DotNet.Example
{
     using DotNet.BaseManager;
     using DotNet.Utilities;
     using DotNet.DbUtilities;

     public  class SchemaTable
    {
         public  void GetSchemaTable()
        {
            SqlConnection connection =  new SqlConnection(BaseSystemInfo.BusinessDbConnection);
            connection.Open();
            DataTable dt = connection.GetSchema( " Tables ");
            connection.Close();
             foreach (DataRow dataRow  in dt.Rows)
            {
                 string tableName = dataRow[ " TABLE_NAME "].ToString();
                 string commandText =  " SELECT COUNT(*) FROM  " + tableName;
                 int rowCount =  int.Parse(DbHelper.ExecuteScalar(commandText).ToString());
                 if (rowCount >  1000)
                {
                    System.Console.WriteLine( " {0,8} {1} ", rowCount, tableName);
                }
            }
        }
    }
}

 

Hope to the starting point and reference.

 

Reproduced in: https: //my.oschina.net/iwenr/blog/227928

Guess you like

Origin blog.csdn.net/weixin_33827731/article/details/91675317