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


C# ISchemaBase.ToSqlDiff方法代码示例

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


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

示例1: alter

        public static string alter(ISchemaBase target, string connectionString)
        {
            var db = target.RootParent as Database;
            if (db != null && DialogResult.Yes != MessageBox.Show(String.Format("Alter {0} {1} in {2}..{3}?\n(WARNING: No automatic backup is made!)",
                    target.ObjectType,
                    target.Name,
                    db.Info.Server,
                    db.Info.Database), "ALTER Destination?", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button2))
            {
                return "Cancelled.";
            }

            string result = string.Empty;

            SqlConnection connection = new SqlConnection(connectionString);
            SQLScriptList SqlDiff = target.ToSqlDiff();
            string[] splitOn = {"GO"};
            string[] tempList = SqlDiff.ToSQL().Split(splitOn, StringSplitOptions.RemoveEmptyEntries);
            List<string> scripts = new List<string>(tempList);

            foreach (string sql in scripts)
            {
                string script = sql;
                //script = script.Replace("\r", "");
                //script = script.Replace("\t", "");
                //script = script.Replace("\n", " ");
                if (target.ObjectType == Enums.ObjectType.StoreProcedure)
                {
                    script = sql.Replace("CREATE PROCEDURE", "ALTER PROCEDURE");
                }
                SqlCommand command = new SqlCommand(script, connection);
                try
                {
                    connection.Open();
                    command.ExecuteNonQuery();
                    connection.Close();
                }
                catch(Exception e)
                {
                    result += target.Name + ": " + e.Message + "\n\n";
                    connection.Close();
                }
            }
            return result;
        }
开发者ID:pclancy,项目名称:ODBX,代码行数:45,代码来源:Updater.cs

示例2: rebuild

 public static string rebuild(ISchemaBase target, string connectionString)
 {
     SQLScriptList SqlDiff = target.ToSqlDiff();
     string[] splitOn = { "GO" };
     string[] tempList = SqlDiff.ToSQL().Split(splitOn, StringSplitOptions.RemoveEmptyEntries);
     List<string> scripts = new List<string>(tempList);
     string result = string.Empty;
     string script = scripts[0];
     if (target.ObjectType == Enums.ObjectType.Table)
     {
         script = script.Replace("CREATE TABLE", "ALTER TABLE");
     }
     MessageBox.Show(script);
     return result;
 }
开发者ID:mi-tettamanti,项目名称:opendbiff,代码行数:15,代码来源:Updater.cs


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