本文整理汇总了C#中SQLHelper.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# SQLHelper.Commit方法的具体用法?C# SQLHelper.Commit怎么用?C# SQLHelper.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLHelper
的用法示例。
在下文中一共展示了SQLHelper.Commit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDatabase
/// <summary>
/// Creates a database out of the structure it is given
/// </summary>
/// <param name="Database">Database structure</param>
/// <param name="ConnectionString">The connection string to the database's location</param>
public static void CreateDatabase(Database Database, string ConnectionString)
{
string Command = BuildCommands(Database);
string[] Splitter = { "\n" };
string[] Commands = Command.Split(Splitter, StringSplitOptions.RemoveEmptyEntries);
ConnectionString = Regex.Replace(ConnectionString, "Pooling=(.*?;)", "", RegexOptions.IgnoreCase) + ";Pooling=false;";
string DatabaseConnectionString = Regex.Replace(ConnectionString, "Initial Catalog=(.*?;)", "", RegexOptions.IgnoreCase);
using (SQLHelper Helper = new SQLHelper(Commands[0], DatabaseConnectionString, CommandType.Text))
{
Helper.ExecuteNonQuery();
}
using (SQLHelper Helper = new SQLHelper("", ConnectionString, CommandType.Text))
{
try
{
Helper.BeginTransaction();
for (int x = 1; x < Commands.Length; ++x)
{
Helper.Command = Commands[x];
Helper.ExecuteNonQuery();
}
Helper.Commit();
}
catch { Helper.Rollback(); throw; }
}
}
示例2: UpdateDatabase
/// <summary>
/// Updates a database (only adds new fields, tables, etc. does not delete old fields)
/// </summary>
/// <param name="DesiredDatabase">The desired structure of the database</param>
/// <param name="CurrentDatabase">The current database structure</param>
/// <param name="ConnectionString">Connection string to the database</param>
public static void UpdateDatabase(Database DesiredDatabase, Database CurrentDatabase, string ConnectionString)
{
if (CurrentDatabase == null)
{
CreateDatabase(DesiredDatabase, ConnectionString);
return;
}
string Command = BuildCommands(DesiredDatabase, CurrentDatabase);
string[] Splitter = { "\n" };
string[] Commands = Command.Split(Splitter, StringSplitOptions.RemoveEmptyEntries);
ConnectionString = Regex.Replace(ConnectionString, "Pooling=(.*?;)", "", RegexOptions.IgnoreCase) + ";Pooling=false;";
using (SQLHelper Helper = new SQLHelper("", ConnectionString, CommandType.Text))
{
try
{
Helper.BeginTransaction();
for (int x = 0; x < Commands.Length; ++x)
{
Helper.Command = Commands[x];
Helper.ExecuteNonQuery();
}
Helper.Commit();
}
catch { Helper.Rollback(); throw; }
}
}