当前位置: 首页>>代码示例>>C#>>正文


C# DataAccess.GetDataTable方法代码示例

本文整理汇总了C#中DataAccess.GetDataTable方法的典型用法代码示例。如果您正苦于以下问题:C# DataAccess.GetDataTable方法的具体用法?C# DataAccess.GetDataTable怎么用?C# DataAccess.GetDataTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataAccess的用法示例。


在下文中一共展示了DataAccess.GetDataTable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CombineAllTalbeScripts

        public static void CombineAllTalbeScripts(string codeRootPath, string connectionString)
        {
            string scriptPath = Path.Combine(codeRootPath, "tables");

            string script =
              "  DECLARE @totalTableCount int                                                                                                            " +
              "  DECLARE @tableListCount int                                                                                                             " +
              "                                                                                                                                          " +
              "  DECLARE @tableList TABLE                                                                                                                " +
              "  (tableID int)                                                                                                                           " +
              "                                                                                                                                          " +
              "  SELECT @totalTableCount = COUNT(1) FROM sys.tables                                                                                      " +
              "                                                                                                                                          " +
              "  INSERT INTO @tableList                                                                                                                  " +
              "  SELECT object_id FROM sys.tables                                                                                                        " +
              "  	WHERE object_id NOT IN                                                                                                               " +
              "  		(SELECT parent_object_id FROM sys.foreign_keys)                                                                                  " +
              "  	ORDER BY [name]	                                                                                                                     " +
              "  	                                                                                                                                     " +
              "  WHILE (EXISTS(                                                                                                                          " +
              "  select * from sys.foreign_keys                                                                                                          " +
              "  	WHERE parent_object_id NOT in                                                                                                        " +
              "  		(SELECT parent_object_id FROM sys.foreign_keys keys LEFT JOIN @tableList tbl ON keys.referenced_object_id = tbl.tableID          " +
              "  				WHERE tbl.tableID is null)                                                                                               " +
              "  	AND referenced_object_id IN (SELECT tableID FROM @tableList)                                                                         " +
              "  	AND parent_object_id NOT IN (SELECT tableID FROM @tableList)                                                                         " +
              "  ))                                                                                                                                      " +
              "  BEGIN                                                                                                                                   " +
              "  	INSERT INTO @tableList                                                                                                               " +
              "  	SELECT distinct parent_object_id FROM sys.foreign_keys                                                                               " +
              "  	WHERE parent_object_id NOT in                                                                                                        " +
              "  		(SELECT parent_object_id FROM sys.foreign_keys keys LEFT JOIN @tableList tbl ON keys.referenced_object_id = tbl.tableID          " +
              "  				WHERE tbl.tableID is null)                                                                                               " +
              "  	AND referenced_object_id IN (SELECT tableID FROM @tableList)                                                                         " +
              "  	AND parent_object_id NOT IN (SELECT tableID FROM @tableList)                                                                         " +
              " END                                                                                                                                      " +
              "                                                                                                                                          " +
              "  INSERT INTO @tableList                                                                                                                  " +
              "  SELECT parent_object_id FROM sys.foreign_keys                                                                                           " +
              "  	WHERE parent_object_id NOT IN                                                                                                        " +
              "  		(SELECT tableID FROM @tableList)                                                                                                 " +
              "  	ORDER BY [name]                                                                                                                      " +
              "                                                                                                                                          " +
              "  		                                                                                                                                 " +
              "  SELECT tableID, name FROM @tableList l INNER JOIN sys.tables t ON l.tableID=t.object_id and t.name not like 'DEL_%'                     ";

            DataAccess da = new DataAccess(connectionString, ProviderType.Sql);
            da.CommandText = script;
            da.CommandType = CommandType.Text;
            DataTable dt = da.GetDataTable();

            StringBuilder sb = new StringBuilder();

            foreach (DataRow row in dt.Rows)
            {
                string path = string.Format("{0}.sql", row["name"]);
                path = Path.Combine(scriptPath, path);

                if (File.Exists(path))
                {
                    sb.AppendFormat("PRINT '**************** {0} *******************'", row["name"]).AppendLine();
                    sb.AppendLine(File.ReadAllText(path));
                }
            }

            string dest = Path.Combine(codeRootPath, "alltables.sql");
            File.WriteAllText(dest, sb.ToString());
        }
开发者ID:kenlinj,项目名称:Easymish,代码行数:68,代码来源:InitDatabase.cs

示例2: GetBaseName

 /// <summary>
 /// Obtiene el nombre de la base de datos actual.
 /// </summary>
 /// <param name="oDA">Conexión actual.</param>
 /// <returns>Nombre de la Base de Datos.</returns>
 public static string GetBaseName(DataAccess oDA)
 {
     try {
         DataTable dt = null;
         oDA.ClearParameters();
         dt = oDA.GetDataTable("SELECT DB_NAME()");
         return dt.Rows[0][0].ToString();
     } catch (DataAccessException ex) {
         throw new CoreException(ex.Message, ex);
     } catch (Exception ex) {
         throw new CoreException("Error no esperado al obtener el nombre de la Base.", ex);
     }
 }
开发者ID:mattrafa206,项目名称:EstudioDelFutbol,代码行数:18,代码来源:Utilities.cs

示例3: GenerateAllRDScripts

        public static void GenerateAllRDScripts(string codeRootPath)
        {
            string conn = "server=10.22.12.43;uid=SCIToolTeam;pwd=SciTool!;database=ResponseDriver;";
            string script = "";
            string type = "";
            DataTable results = new DataTable();
            DataTable dt;
            DataTable dtTemp;

            results.Columns.Add("Type");
            results.Columns.Add("Name");
            results.Columns.Add("Script");

            DataAccess da = new DataAccess(conn, ProviderType.Sql);

            #region scripts except foreign key
            da.CommandType = System.Data.CommandType.Text;
            da.CommandText = "SELECT * FROM sys.objects ORDER BY [type], [name]";
            dt = da.GetDataTable();
            int i = 0;

            foreach (DataRow row in dt.Rows)
            {
                i++;
                Console.WriteLine("Processing {0:d4}: {1}.{2}", i, row["Type"], row["Name"]);
                switch (row["Type"].ToString().Trim())
                {
                    case "D":   //default value is set in table script
                    case "F":   //FOREIGN KEY
                    case "PK":  //primary key is set in table script
                    case "S":   //SYSTEM_TABLE
                        type = "";
                        break;
                    case "FN":  //SQL_SCALAR_FUNCTION
                    case "IF":  //SQL_INLINE_TABLE_VALUED_FUNCTION
                    case "TF":  //SQL_TABLE_VALUED_FUNCTION
                        type = "Functions";
                        break;
                    case "P":   //SQL_STORED_PROCEDURE
                        type = "Stored Procedures";
                        break;
                    case "TR":  //SQL_TRIGGER
                        type = "Triggers";
                        break;
                    case "V":   //VIEW
                        type = "Views";
                        break;
                    case "FS":  //CLR_SCALAR_FUNCTION
                        type = "CLR Functions";
                        break;
                    case "PC":  //CLR_STORED_PROCEDURE
                        type = "CLR Stored Procedures";
                        break;
                    case "U":
                        type = "Tables";
                        break;
                    case "UQ":
                        type = "Unique Index";
                        break;
                }

                switch (row["Type"].ToString().Trim())
                {
                    case "D":   //default value is set in table script
                    case "F":   //FOREIGN KEY
                    case "PK":  //primary key is set in table script
                    case "S":   //SYSTEM_TABLE
                    case "IT":
                    case "SQ":
                        script = null;
                        break;
                    case "FS":  //CLR_SCALAR_FUNCTION
                    case "PC":  //CLR_STORED_PROCEDURE
                        script = "Encrypted";
                        break;
                    case "FN":  //SQL_SCALAR_FUNCTION
                    case "IF":  //SQL_INLINE_TABLE_VALUED_FUNCTION
                    case "P":   //SQL_STORED_PROCEDURE
                    case "TF":  //SQL_TABLE_VALUED_FUNCTION
                    case "TR":  //SQL_TRIGGER
                    case "V":   //VIEW
                        //script = null;
                        script = "sp_helptext " + row["Name"].ToString();

                        da.CommandText = script;
                        dtTemp = da.GetDataTable();

                        script = "";
                        foreach (DataRow rowTemp in dtTemp.Rows)
                        {
                            script += rowTemp[0];
                        }
                        break;
                    case "U":
                        script =
                        #region generate create table script
             "declare @table sysname                                                                 " +

                            "set @table = '{0}'                                                    " +

//.........这里部分代码省略.........
开发者ID:kenlinj,项目名称:Easymish,代码行数:101,代码来源:InitDatabase.cs


注:本文中的DataAccess.GetDataTable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。