本文整理汇总了C#中IConnection.ExecuteScalar方法的典型用法代码示例。如果您正苦于以下问题:C# IConnection.ExecuteScalar方法的具体用法?C# IConnection.ExecuteScalar怎么用?C# IConnection.ExecuteScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IConnection
的用法示例。
在下文中一共展示了IConnection.ExecuteScalar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PurchaseExists
public bool PurchaseExists(int item, int purchaser, IConnection conn)
{
const string sql = "SELECT COUNT([purchaseId]) AS PurchaseId FROM dbo.purchase WHERE itemFK = @itemFK and purchaserFK = @purchaserFK;";
List<SqlParameter> prms = new List<SqlParameter>();
prms.Add(new SqlParameter { ParameterName = "@itemFK", Value = item });
prms.Add(new SqlParameter { ParameterName = "@purchaserFK", Value = purchaser });
return ((int)conn.ExecuteScalar(sql,prms) >= 1);
}
示例2: Insert
public int Insert(PersonEntity person, IConnection conn)
{
CheckPersonForRequiredValues(person, RepositoryUtils.RepositoryAction.Insert);
var contactExists = GetPersonByEmail(person.emailAddress);
if (contactExists != null)
{
throw new Exception($"Entity {person.emailAddress} already exists in database!");
}
string sql =
@"INSERT INTO[dbo].[person] (userName, emailAddress, firstName, lastName, passwordHash, updateTimestamp)
VALUES(@userName, @emailAddress, @firstName, @lastName, @passwordHash, getdate());SELECT CAST(scope_identity() AS int)";
List<SqlParameter> prms = new List<SqlParameter>();
prms.Add(new SqlParameter { ParameterName = "@userName", Value = person.userName });
prms.Add(new SqlParameter { ParameterName = "@emailAddress", Value = person.emailAddress });
prms.Add(new SqlParameter { ParameterName = "@firstName", Value = person.firstName });
prms.Add(new SqlParameter { ParameterName = "@lastName", Value = person.lastName });
prms.Add(new SqlParameter { ParameterName = "@passwordHash", Value = person.passwordHash });
try
{
return int.Parse(conn.ExecuteScalar(sql,prms).ToString());
}
catch (Exception)
{
throw new Exception($"Entity {person.firstName} {person.lastName} not inserted in database!");
}
}
示例3: Insert
public long Insert(PurchaseEntity purchase, IConnection conn)
{
CheckPurchaseForRequiredValues(purchase, RepositoryUtils.RepositoryAction.Insert);
var purchaseExists = GetPurchase(purchase.itemFK, purchase.purchaserFK);
if (purchaseExists != null)
{
throw new Exception($"Entity {purchase.itemFK}, {purchase.purchaserFK} already exists in database!");
}
string sql =
@"INSERT INTO[dbo].[purchase] (itemFK, purchaserFK, purchaseDate, updateTimestamp, updatePersonFK)
VALUES(@itemFk, @purchaserFK, @purchaseDate, getdate(), @updatePersonKey);SELECT CAST(scope_identity() AS int)";
List<SqlParameter> prms = new List<SqlParameter>();
prms.Add(new SqlParameter { ParameterName = "@itemFK", Value = purchase.itemFK });
prms.Add(new SqlParameter { ParameterName = "@purchaserFK", Value = purchase.purchaserFK });
prms.Add(new SqlParameter { ParameterName = "@purchaseDate", Value = purchase.purchaseDate });
prms.Add(new SqlParameter { ParameterName = "@updatePersonFK", Value = purchase.updatePersonFK });
try
{
return int.Parse(conn.ExecuteScalar(sql,prms).ToString());
}
catch (Exception)
{
throw new Exception($"Entity {purchase.itemFK} {purchase.purchaserFK} not inserted in database!");
}
}
示例4: GroupMemberExists
public bool GroupMemberExists(int group, int member, IConnection conn)
{
string sql = "SELECT groupMemberId, groupFK, memberFK, isAdmin, updateTimestamp, updatePersonFK FROM DBO.GROUPMEMBER WHERE groupFK = @groupFK and itemFK = @itemFK;";
List<SqlParameter> prms = new List<SqlParameter>();
var param1 = new SqlParameter
{
ParameterName = "@groupFK",
Value = group
};
prms.Add(param1);
var param2 = new SqlParameter
{
ParameterName = "@memberFK",
Value = member
};
prms.Add(param2);
return ((int)conn.ExecuteScalar(sql,prms) >= 1);
}
示例5: GetNumberOfItemComments
public long GetNumberOfItemComments(int item, IConnection conn)
{
string sql = "SELECT COUNT(itemCommentId) FROM DBO.PERSON WHERE itemFK LIKE @item;";
List<SqlParameter> prms = new List<SqlParameter>();
var paramQuery = new SqlParameter
{
ParameterName = "@item",
Value = item
};
prms.Add(paramQuery);
return Int32.Parse(conn.ExecuteScalar(sql,prms).ToString());
}
示例6: LinkExists
public bool LinkExists(int item, string linkName, IConnection conn)
{
const string sql = "SELECT COUNT([linkId]) AS LinkId FROM dbo.link WHERE itemFK = @itemFK AND linkName = @linkName;";
List<SqlParameter> prms = new List<SqlParameter>();
prms.Add(new SqlParameter { ParameterName = "@itemFK", Value = item });
prms.Add(new SqlParameter { ParameterName = "@linkName", Value = linkName });
return ((int)conn.ExecuteScalar(sql,prms) >= 1);
}
示例7: GiftListGroupExists
public bool GiftListGroupExists(int giftList, int group, IConnection conn)
{
const string sql = "SELECT COUNT([giftListGroupId]) FROM dbo.giftListGroup WHERE giftListFK = @giftListFK AND groupFK = @groupFK;";
List<SqlParameter> prms = new List<SqlParameter>();
var param1 = new SqlParameter
{
ParameterName = "@giftListFK",
Value = giftList
};
prms.Add(param1);
var param2 = new SqlParameter
{
ParameterName = "@groupFK",
Value = group
};
prms.Add(param2);
return ((int)conn.ExecuteScalar(sql,prms) >= 1);
}
示例8: GetNumberOfItems
public long GetNumberOfItems(int giftList, IConnection conn)
{
string sql = "SELECT COUNT(itemId) FROM dbo.item WHERE giftListFK = @giftListFK;";
List<SqlParameter> prms = new List<SqlParameter>();
prms.Add(new SqlParameter { ParameterName = "@giftListFK", Value = giftList });
return Int32.Parse(conn.ExecuteScalar(sql,prms).ToString());
}
示例9: Insert
public long Insert(ItemEntity item, IConnection conn)
{
CheckItemForRequiredValues(item, RepositoryUtils.RepositoryAction.Insert);
var itemExists = ItemExists(item.giftListFK, item.itemName);
if (!itemExists)
{
throw new Exception($"Entity {item.giftListFK} {item.itemName} already exists in database!");
}
string sql =
@"INSERT INTO[dbo].[person] (itemStatusFK, giftListFK, itemName, description, updateTimestamp, updatePersonFK)
VALUES(@itemStatusFK, @giftListFK, @itemName, @description, getdate(), @updatePersonFK);SELECT CAST(scope_identity() AS int)";
List<SqlParameter> prms = new List<SqlParameter>();
prms.Add(new SqlParameter { ParameterName = "@itemStatusFK", Value = item.itemStatusFK });
prms.Add(new SqlParameter { ParameterName = "@giftListFK", Value = item.giftListFK });
prms.Add(new SqlParameter { ParameterName = "@itemName", Value = item.itemName });
prms.Add(new SqlParameter { ParameterName = "@description", Value = item.description });
prms.Add(new SqlParameter { ParameterName = "@updatePersonFK", Value = item.updatePersonFK });
try
{
return int.Parse(conn.ExecuteScalar(sql, prms).ToString());
}
catch (Exception)
{
throw new Exception($"Entity {item.giftListFK} {item.itemName} not inserted in database!");
}
}
示例10: GroupExists
public bool GroupExists(int creator, string groupName, IConnection conn)
{
const string sql = "SELECT COUNT([groupId]) FROM dbo.[group] WHERE creatorFK = @creatorFK AND groupName = @groupName;";
List<SqlParameter> prms = new List<SqlParameter>();
var param1 = new SqlParameter
{
ParameterName = "@creatorFK",
Value = creator
};
prms.Add(param1);
var param2 = new SqlParameter
{
ParameterName = "@groupName",
Value = groupName
};
prms.Add(param2);
return ((int)conn.ExecuteScalar(sql,prms) >= 1);
}
示例11: Insert
public long Insert(GroupEntity group, IConnection conn)
{
var groupExists = GetGroup(group.creatorFK, group.groupName);
if (groupExists != null)
{
throw new Exception($"Entity {group.creatorFK} {group.groupName} already exists in database!");
}
string sql =
@"INSERT INTO[dbo].[link] (creatorFK, groupName, description, isPrivate, updateTimestamp, updatePersonFK)
VALUES(@creatorFK, @groupName, @description, @isPrivate, getdate(), @updatePersonFK );SELECT CAST(scope_identity() AS int)";
List<SqlParameter> prms = new List<SqlParameter>();
var param1 = new SqlParameter
{
ParameterName = "@creatorFK",
Value = group.creatorFK
};
prms.Add(param1);
var param2 = new SqlParameter
{
ParameterName = "@groupName",
Value = group.groupName
};
prms.Add(param2);
var param3 = new SqlParameter
{
ParameterName = "@description",
Value = group.description
};
prms.Add(param3);
var param4 = new SqlParameter
{
ParameterName = "@isPrivate",
Value = group.isPrivate ? 'Y' : 'N'
};
prms.Add(param4);
var param5 = new SqlParameter
{
ParameterName = "@updatePersonFK",
Value = group.updatePersonFK
};
prms.Add(param5);
try
{
return int.Parse(conn.ExecuteScalar(sql,prms).ToString()); ;
}
catch (Exception)
{
throw new Exception($"Entity {group.creatorFK} {group.groupName} not inserted in database!");
}
}
示例12: GetNumberOfGroups
public long GetNumberOfGroups(int creator, IConnection conn)
{
string sql = "SELECT COUNT(groupId) FROM dbo.[group] WHERE creatorFK = @creatorFK;";
List<SqlParameter> prms = new List<SqlParameter>();
var paramQuery = new SqlParameter
{
ParameterName = "@creatorFK",
Value = creator
};
prms.Add(paramQuery);
return Int32.Parse(conn.ExecuteScalar(sql,prms).ToString());
}
示例13: PersonExistsByUserName
public bool PersonExistsByUserName(string userName, IConnection conn)
{
const string sql = "SELECT COUNT([personId]) AS ContactsId FROM dbo.person WHERE userName = @userName;";
List<SqlParameter> prms = new List<SqlParameter>();
prms.Add(new SqlParameter { ParameterName = "@userName", Value = userName });
return ((int)conn.ExecuteScalar(sql,prms) >= 1);
}
示例14: PersonExistsByEmail
public bool PersonExistsByEmail(string email, IConnection conn)
{
const string sql = "SELECT COUNT([personId]) AS ContactsId FROM dbo.person WHERE emailAddress = @emailAddress;";
List<SqlParameter> prms = new List<SqlParameter>();
prms.Add(new SqlParameter { ParameterName = "@emailAddress", Value = email });
return ((int)conn.ExecuteScalar(sql,prms) >= 1);
}
示例15: GetNumberOfLinks
public long GetNumberOfLinks(int item, IConnection conn)
{
string sql = "SELECT COUNT(linkId) FROM DBO.LINK WHERE itemFK = @itemFK;";
List<SqlParameter> prms = new List<SqlParameter>();
prms.Add(new SqlParameter { ParameterName = "@itemFK", Value = item });
return Int32.Parse(conn.ExecuteScalar(sql,prms).ToString());
}