本文整理汇总了C#中DBHelper.ExecuteScalar方法的典型用法代码示例。如果您正苦于以下问题:C# DBHelper.ExecuteScalar方法的具体用法?C# DBHelper.ExecuteScalar怎么用?C# DBHelper.ExecuteScalar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBHelper
的用法示例。
在下文中一共展示了DBHelper.ExecuteScalar方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnDataOperClearLog_Click
/// <summary>
/// 点击“清除日志”
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnDataOperClearLog_Click(object sender, EventArgs e)
{
try
{
if (DataSetOper.Count() > 0)
{
foreach (var item in DataSetOper.Select(c => dataSourceList[c]))
{
DBHelper db = new DBHelper(item, providerName);
//因为ExecuteNonQuery方法不支持多个sql语句之间用GO连接,因此拆成多次执行
var SqlVersion = db.ExecuteScalar("select @@version").ToString();
if (SqlVersion.IndexOf("2005") > 0)
{
db.ExecuteNonQuery(string.Format("Backup Log {0} with no_log", db.DataBaseName));
db.ExecuteNonQuery(string.Format("dump transaction {0} with no_log", db.DataBaseName));
db.ExecuteNonQuery(string.Format(@"USE [{0}]
DBCC SHRINKFILE ( 2 )", db.DataBaseName));
}
else if (SqlVersion.IndexOf("2008") > 0)
{
var logName = db.ExecuteScalar("select name from sys.database_files where type='1'");
db.ExecuteNonQuery(string.Format(@"USE [master]
ALTER DATABASE {0} SET RECOVERY SIMPLE WITH NO_WAIT", db.DataBaseName));
db.ExecuteNonQuery(string.Format(@"ALTER DATABASE {0} SET RECOVERY SIMPLE -- 简单模式 ", db.DataBaseName));
db.ExecuteNonQuery(string.Format(@"DBCC SHRINKFILE (N'{0}' , 11 , TRUNCATEONLY)", logName));
db.ExecuteNonQuery(string.Format(@"USE [master]
ALTER DATABASE {0} SET RECOVERY FULL WITH NO_WAIT", db.DataBaseName));
db.ExecuteNonQuery(string.Format(@"USE [master]
ALTER DATABASE {0} SET RECOVERY FULL -- 还原为完全模式 ", db.DataBaseName));
}
}
MessageBox.Show("执行成功");
}
else
MessageBox.Show("请选择数据源");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}