高手请进,select count(*) 查询结果为空,而不是所需要的0

ntlh21cn 2007-03-29 04:33:09
我在SqlDataSource1对象的Select语句如下:
select count(*) from table1 where row1=@row1;
将参数@row1 与this.textbox1相关联后
如果textbox1为空时,查询结果为空,而不是0;
而为希望为0;
请问怎么办?

我用的是vs2005
...全文
437 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
lhfdc 2007-03-31
  • 打赏
  • 举报
回复
select isnull(count(*),0) from table where section=
@section
xinfan 2007-03-31
  • 打赏
  • 举报
回复
你这样试试
select count(*) as iCount from table1 where row1=@row1;
//起个别名 然后取数
ntlh21cn 2007-03-29
  • 打赏
  • 举报
回复
可是我是要加入参数的呀?
tinki 2007-03-29
  • 打赏
  • 举报
回复
select count(*) as num from table1 where row1='',
select count(*) as num table1 where row1=null,
select count(*) as num table1 where row1=1,
select count(*) as num table1 where row1='1',
select count(*) as num table1 where row1=''''//单引号要转换为双引号
ntlh21cn 2007-03-29
  • 打赏
  • 举报
回复
job_2006说的方法试了,连有字符时也出不来了.
我是用DetailsView1显示结果的

我的代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
输入:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Button" /><br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:HFC2ConnectionString %>"
SelectCommand="SELECT COUNT(*) AS 数量 FROM 口令表 WHERE (操作员 = @操作员)">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" DefaultValue="" Name="操作员" PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="SqlDataSource1"
Height="50px" Width="125px">
</asp:DetailsView>

</div>
</form>
</body>
</html>
hmilyfm 2007-03-29
  • 打赏
  • 举报
回复
断点撒
confei 2007-03-29
  • 打赏
  • 举报
回复
同意楼上
select isnull(count(*),0) from table1 where row1=@row1;
job_2006 2007-03-29
  • 打赏
  • 举报
回复
select isnull(count(*),0) from table1 where row1=@row1;
ntlh21cn 2007-03-29
  • 打赏
  • 举报
回复
可如textbox中有字符时,结果能正常出来
如用session关联付一个" "空格,结果也正常
真相重于对错 2007-03-29
  • 打赏
  • 举报
回复
code??
北京的雾霾天 2007-03-29
  • 打赏
  • 举报
回复
比如字符串格式不正确等等的错误.
北京的雾霾天 2007-03-29
  • 打赏
  • 举报
回复
可能是因为语法出错了,而没有正常的执行Sql语句.
lovehongyun 2007-03-29
  • 打赏
  • 举报
回复
sf

62,039

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧