如果通过查询来判断呢?
比如说,我们通过一个字段查询数据库有没有这个数据,如果有就显示“有”,如果没有就显示“没有” string sql = "select * from Zhengshu where UserName like '%" + txtBox + "%'";查询会写了,但还少一个值来判断啊,高手救一下,两年没有碰.NET 了。
比如说,我们通过一个字段查询数据库有没有这个数据,如果有就显示“有”,如果没有就显示“没有” string sql = "select * from Zhengshu where UserName like '%" + txtBox + "%'";查询会写了,但还少一个值来判断啊,高手救一下,两年没有碰.NET 了。
解决方案 »
- 求帮助,ASP.NET登入页面第一次打开的时候CSS样式没有加载yunx,跳转到其他页面再回到登入页面样式就都显示出来了,请问这是咋情况
- asp.net 怎么解决上传大视频文件?
- 使用GridView
- switch case 如何使用定义成常量的几个int常量。
- 网页上的tab控件是如何做的
- [讨论]关于URL重写的问题
- (我没分了,请大家可怜可怜我把!)为什么呢?F:\lwei\lwei\display.aspx.cs(51): 找不到类型或命名空间名称“SqlConnection”(是否缺少
- DataGrid中的DropDownList列无法获取当前选中的值的问题
- 如何在1个datagrid中显示2个table中的内容
- 那位朋友有自定义控件的代码,???
- 为什么看有的网站的每个栏目都在文件夹里看不到扩展名
- 问几个基础问题
string sql = "select count(ID) from Zhengshu where UserName like '%" + txtBox + "%'";
用ExecuteScalar 返回判断
大于0 就是有
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
//SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ToString ());
con.Open();
SqlCommand com = new SqlCommand(sql, con);
try
{
int isEx = Convert.ToInt32(com.ExecuteScalar());
if (isEx > 0)
{
con.Close();
return "有";
}
else
{
con.Close();
return “木有”;
}
}
catch
{
return “挂了”;
}
}
返回到DataTable里。然后判断DataTable.Rows.Count
SELECT CASE num1 when 0 then '木有' ELSE '有' end From (select count(*) from Zhengshu where UserName like '%" + txtBox + "%'") as tb1
case when y > 0
then '有'
else
'没有'
end
from (select count(1) y from Zhengshu c where c.UserName '%" + txtBox + "%'")
)