本文整理汇总了C#中Westwind.Utilities.Data.SqlDataAccess.ExecuteScalar方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDataAccess.ExecuteScalar方法的具体用法?C# SqlDataAccess.ExecuteScalar怎么用?C# SqlDataAccess.ExecuteScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Westwind.Utilities.Data.SqlDataAccess
的用法示例。
在下文中一共展示了SqlDataAccess.ExecuteScalar方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UdateEntityTest
public void UdateEntityTest()
{
using (var data = new SqlDataAccess(STR_ConnectionString))
{
int id = (int) data.ExecuteScalar("select TOP 1 id from customers order by entered");
Console.WriteLine(id);
Customer customer = new Customer()
{
Id = id,
FirstName = "Updated Entry " + DateTime.UtcNow,
Entered = DateTime.UtcNow,
Updated = DateTime.UtcNow
};
// insert into customers and skip Id,Order properties and return id
object newId = data.UpdateEntity(customer, "Customers", "Id", null, "Id,Orders");
Assert.IsNotNull(newId, data.ErrorMessage);
Console.WriteLine(newId);
}
}
示例2: NewParametersTableTest
public void NewParametersTableTest()
{
var data = new SqlDataAccess(STR_ConnectionString);
// warmup
data.ExecuteScalar("select top1 id from ApplicationLog");
//var cmd = data.CreateCommand("select * from ApplicationLog where entered > @0 and entered > @1",CommandType.Text, DateTime.Now.AddYears(-10), DateTime.Now.AddYears(-));
//var table = data.ExecuteTable("TLogs", cmd);
var swatch = Stopwatch.StartNew();
var table = data.ExecuteTable("TLogs",
"select * from ApplicationLog where entered > @0 and entered < @1 order by Entered",
DateTime.Now.AddYears(-115), DateTime.Now.AddYears(-1));
Assert.IsNotNull(table, data.ErrorMessage);
Console.WriteLine(table.Rows.Count);
foreach (DataRow row in table.Rows)
{
Console.WriteLine(((DateTime) row["Entered"]));
}
swatch.Stop();
Console.WriteLine(swatch.ElapsedMilliseconds + "ms");
}
示例3: IsLocalizationTable
/// <summary>
/// Checks to see if the LocalizationTable exists
/// </summary>
/// <param name="TableName"></param>
/// <returns></returns>
public bool IsLocalizationTable(string TableName)
{
if (TableName == null)
TableName = DbResourceConfiguration.Current.ResourceTableName;
SqlDataAccess Data = new SqlDataAccess(DbResourceConfiguration.Current.ConnectionString);
// Check for table existing already
object Pk = Data.ExecuteScalar("select count(pk) from " + TableName);
if (Pk is int)
return true;
return false;
}
示例4: GetResourceString
/// <summary>
/// Returns an individual Resource String from the database
/// </summary>
/// <param name="resourceId"></param>
/// <param name="resourceSet"></param>
/// <param name="cultureName"></param>
/// <returns></returns>
public string GetResourceString(string resourceId, string resourceSet, string cultureName)
{
SetError();
if (cultureName == null)
cultureName = string.Empty;
object result;
using (var data = new SqlDataAccess(DbResourceConfiguration.Current.ConnectionString))
{
result = data.ExecuteScalar("select Value from " + DbResourceConfiguration.Current.ResourceTableName +
" where [email protected] and [email protected] and [email protected]",
data.CreateParameter("@ResourceId", resourceId),
data.CreateParameter("@ResourceSet", resourceSet),
data.CreateParameter("@LocaleId", cultureName));
}
return result as string;
}
示例5: ResourceExists
/// <summary>
/// Checks to see if a resource exists in the resource store
/// </summary>
/// <param name="ResourceId"></param>
/// <param name="Value"></param>
/// <param name="CultureName"></param>
/// <param name="ResourceSet"></param>
/// <returns></returns>
public bool ResourceExists(string ResourceId, string CultureName, string ResourceSet)
{
if (CultureName == null)
CultureName = string.Empty;
object Result = null;
using (SqlDataAccess Data = new SqlDataAccess(DbResourceConfiguration.Current.ConnectionString))
{
Result = Data.ExecuteScalar("select ResourceId from " + DbResourceConfiguration.Current.ResourceTableName + " where [email protected] and [email protected] and [email protected] group by ResourceId",
Data.CreateParameter("@ResourceId", ResourceId),
Data.CreateParameter("@LocaleId", CultureName),
Data.CreateParameter("@ResourceSet", ResourceSet));
if (Result == null)
return false;
}
return true;
}