当前位置:编程学习 > VB >>

ExcuteScalar问题

select count(uid) from db_user 
where 
uid !='1222222' 
and 
uid not in 
(select fromid from db_friend where toid ='1222222') 
and 
usex = '女'
这条语句在数据库中执行返回正确的结果,但是在程序里用ExcuteScalar返回的结果却是0
这是怎么回事呢? 程序里用ExcuteScalar 怎么用的?  string sql = "select count(uid) from db_user where uid !='" + uid + "'";

            if (uid != "" && uid != null)
            {

                if (name != "" && name != null)
                {
                    sql += " and name like '%" + name + "%'";
                }

                if (usex != "0" && usex != null)
                {
                    sql += " and usex = '" + usex + "'";
                }

                if (address != "0" && address != null)
                {
                    sql += " and uaddress = '" + address + "'";
                }

                if (job != 0)
                {
                    sql += " and ujob = " + job;
                }
            }

            int res = DBHelper.GetScalar(sql);
            return res;


public static int GetScalar(string safeSql)
        {
            SqlCommand cmd = new SqlCommand(safeSql, Connection);
            int result = Convert.ToInt32(cmd.ExecuteScalar());
            cmd.Connection.Close();
            cmd.Connection.Dispose();
            return result;
        } 你确定用的是VB么? asp.net
补充:VB ,  数据库(包含打印,安装,报表)
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,