查询后如何计算行数? [英] How to count number of rows after query?

查看:72
本文介绍了查询后如何计算行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个新问题.
我的进程:

I have a new problem.
My proc:

create proc sp_Login
	@UserName char(10),
	@passW char(10)
as
	select * from User where UserName=@UserName and passw=@passw
go





public string Login(string user, string passw)
    {
        DataContextDataContext dcon=new DataContextDataContext();
        string msg = "";
        var q = dcon.sp_Login("John","123");
        if (q.Count() > 0)
        {
            msg="hi"+"john";
        return kq;
    }


推荐答案

只需将您的SP更改为:
Just change your SP to:
select COUNT(*) from User where UserName=@UserName and passw=@passw



您只需要计数而无需其他.此外,您不应无故找回密码.

根据现在检索的内容处理代码中的更改.



You need just the count and nothing else. Further, you should not retrieve the password without any reason.

Handle the change in your code according to what is now retrieved back.



您可以使用@@ROWCOUNT
http://msdn.microsoft.com/en-us/library/ms188774.aspx [ ^ ]
http://technet.microsoft.com/en-us/library/ms187316.aspx [ ^ ]
最好的问候
M.Mitwalli
Hi ,
You can use @@ROWCOUNT
http://msdn.microsoft.com/en-us/library/ms188774.aspx[^]
http://technet.microsoft.com/en-us/library/ms187316.aspx[^]
Best Regards
M.Mitwalli


create proc sp_Login
	@UserName char(10),
	@passW char(10)
as
	select count(*) from User where UserName=@UserName and passw=@passw
go


Collapse | Copy Code

public string Login(string user, string passw)
    {
        DataContextDataContext dcon=new DataContextDataContext();
        string msg = "";
        var q = dcon.sp_Login("John","123");
        if (q.Count() > 0)
        {
            msg="hi"+ user;
        return kq;
    }


这篇关于查询后如何计算行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆