我正在使用数据库创建一个简单的登录页面。 因此,对于我的查询,我使用的是Dapper,而我在以下查询中受阻。
d = {} # empty dict
loc = location(282, 285, 284, 283)
values = ' '.join([str(i.id) for i in loc])
key = 'loc1'
d[key] = values
因此,如果“ count(Id)as Id”部分返回1,则表示登录正确。 如果返回0,则表示错误。
但是如何将“ count(Id)as Id”中的数据转换为可以使用的数据呢?
答案 0 :(得分:6)
Execute
执行非查询操作(通常是insert
或delete
,什么都不select
)。您需要一种Query
方法-最方便的方法可能是QuerySingle<int>
,因为您希望恰好是一个int
值。
int count = connection.QuerySingle<int>(@"SELECT count(Id) as Id FROM tblMedewerkers
where Naam = @Naam and Paswoord = @Paswoord",
new{
Naam = naam,
Paswoord = paswoord
});