本文整理匯總了C#中Westwind.Utilities.Data.SqlDataAccess.BeginTransaction方法的典型用法代碼示例。如果您正苦於以下問題:C# SqlDataAccess.BeginTransaction方法的具體用法?C# SqlDataAccess.BeginTransaction怎麽用?C# SqlDataAccess.BeginTransaction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Westwind.Utilities.Data.SqlDataAccess
的用法示例。
在下文中一共展示了SqlDataAccess.BeginTransaction方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: RestoreBackupTable
/// <summary>
/// Restores the localization table from a backup table by first wiping out
/// </summary>
/// <param name="backupTableName"></param>
/// <returns></returns>
public bool RestoreBackupTable(string backupTableName)
{
if (backupTableName == null)
backupTableName = DbResourceConfiguration.Current.ResourceTableName + "_Backup";
using (var data = new SqlDataAccess(DbResourceConfiguration.Current.ConnectionString))
{
data.BeginTransaction();
if (data.ExecuteNonQuery("delete from " + DbResourceConfiguration.Current.ResourceTableName) < 0)
{
data.RollbackTransaction();
ErrorMessage = data.ErrorMessage;
return false;
}
string sql =
@"insert into {0}
(ResourceId,Value,LocaleId,ResourceSet,Type,BinFile,TextFile,FileName,Comment)
select ResourceId,Value,LocaleId,ResourceSet,Type,BinFile,TextFile,FileName,Comment from {1}";
sql = string.Format(sql, DbResourceConfiguration.Current.ResourceTableName, backupTableName);
if (data.ExecuteNonQuery(sql) < 0)
{
data.RollbackTransaction();
ErrorMessage = data.ErrorMessage;
return false;
}
data.CommitTransaction();
}
return true;
}
示例2: GenerateResources
/// <summary>
/// Persists resources to the database - first wipes out all resources, then writes them back in
/// from the ResourceSet
/// </summary>
/// <param name="ResourceList"></param>
/// <param name="CultureName"></param>
/// <param name="BaseName"></param>
public bool GenerateResources(IDictionary ResourceList, string CultureName, string BaseName, bool DeleteAllResourceFirst)
{
if (ResourceList == null)
throw new InvalidOperationException("No Resources");
if (CultureName == null)
CultureName = string.Empty;
using (SqlDataAccess Data = new SqlDataAccess(DbResourceConfiguration.Current.ConnectionString))
{
if (!Data.BeginTransaction())
return false;
// Set transaction to be shared by other methods
Transaction = Data.Transaction;
try
{
// First delete all resources for this resource set
if (DeleteAllResourceFirst)
{
int Result = Data.ExecuteNonQuery("delete " + DbResourceConfiguration.Current.ResourceTableName + " where [email protected] and [email protected]",
Data.CreateParameter("@LocaleId", CultureName),
Data.CreateParameter("@ResourceSet", BaseName));
if (Result == -1)
{
Data.RollbackTransaction();
return false;
}
}
// Now add them all back in one by one
foreach (DictionaryEntry Entry in ResourceList)
{
if (Entry.Value != null)
{
int Result = 0;
if (DeleteAllResourceFirst)
Result = AddResource(Entry.Key.ToString(), Entry.Value, CultureName, BaseName, null);
else
Result = UpdateOrAdd(Entry.Key.ToString(), Entry.Value, CultureName, BaseName, null);
if (Result == -1)
{
Data.RollbackTransaction();
return false;
}
}
}
}
catch
{
Data.RollbackTransaction();
return false;
}
Data.CommitTransaction();
}
// Clear out the resources
ResourceList = null;
return true;
}