C#中当参数为空时的几种处理

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/zhongxinhua0123/article/details/70621139

C#中当参数为空时的几种处理:(直接在C#后台进行处理)
1.浮点型:

BuildingArea =string.IsNullOrWhiteSpace(num_BuildingArea.Text.Trim()) ? 0 : decimal.Parse(num_BuildingArea.Text.Trim());

2.整形:

LandType = string.IsNullOrWhiteSpace(ddl_LandType.SelectedValue) ? 0 : int.Parse(ddl_LandType.SelectedValue);

3,日期:(对数据库操作尤其有用)

CompletionDate = datepic_CompletionDate.Text.ConvertTo<DateTime?>();//值可以为空
展开阅读全文

怎样控制当上传文件为空时的处理

07-17

提交在前一页面处理,这个是上传文件,请给出程序rn代码如下:rn<%Response.Buffer = TRUE %>rnrnrn 文件上传rn rnrnrn<%rn on error resume nextrn '生成随机文件名rn function makefilename(fname)rn fname = now()rn fname = replace(fname,"-","")rn fname = replace(fname," ","") rn fname = replace(fname,":","")rn fname = replace(fname,"PM","")rn fname = replace(fname,"AM","")rn fname = replace(fname,"上午","")rn fname = replace(fname,"下午","")rn makefilename=fname rn end function rntarg=request("targ")rnflder=server.MapPath(targ) rnset fsf=Server.CreateObject("Scripting.FileSystemObject") rnif not fsf.FolderExists(flder) thenrn fsf.CreateFolder flderrnend ifrnuppath=flder+"\"rnServer.ScriptTimeOut=9000rnset upload = server.CreateObject("uploadfilecom.uploadfile")rnfname=upload.FileName("T1")rnfsize=upload.FileSize("T1")rnN1instring=instr(fname,"\")rnN2instring=instr(fname,"/")rndo while N1instring-N2instring<>0rn if n1instring>0 thenrn fname=right(fname,len(fname)-instr(fname,"\"))rn end ifrn if n2instring>0 thenrn fname=right(fname,len(fname)-instr(fname,"/"))rn end ifrn N2instring=instr(fname,"/")rn N1instring=instr(fname,"\")rnloop rnrnupload.SaveTo(flder) rnsession("inputfile")=truern'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ rn newfname=makefilename(now())&mid(fname,len(fname)-3,4)rn fsf.CopyFile uppath&fname,uppath&newfname,truern fsf.DeleteFile uppath&fname,true rn set fsf=nothing rn%>rn 论坛

行转列 当临时表为空时

12-06

行转列的数据来自临时表,如果临时数据为空时会报错,,用的是邹老大的代码,如何判断临时表的数据是否为空,如果为空直接返回0,有数据才做行转列:数据如下:rn[code=SQL]rndeclare @sqlhead varchar(8000),@sqlend varchar(8000) rn ,@sql1 varchar(8000),@sql2 varchar(8000),@sql3 varchar(8000),@sql4 varchar(8000) rn ,@i int,@ic varchar(20) rnrn --生成数据处理临时表 rn select id=identity(int,0,1),gid=0 rn ,a=',['+[name] +']=max(case [name] when ''' rn +[name]+''' then ThresholdValue else 0 end)' rn into # from(select distinct [name] from #tempSensorLabel) a rnrn --判断需要多少个变量来处理 rn select @i=max(len(a)) from # rn print @i rn set @i=4000/@i rnrn --分组临时表 rn update # set gid=id/@i rn select @i=max(gid) from # rnrn --生成数据处理语句 rn select @sqlhead='''select SiteName,MacSerialNumber ''' rn ,@sqlend=''' from #tempSensorLabel group by SiteName,MacSerialNumber ''' rn ,@sql1='',@sql2='select ',@sql3='',@sql4='' rnrn while @i> =0 rn select @ic=cast(@i as varchar),@i=@i-1 rn ,@sql1='@'+@ic+' varchar(8000),'+@sql1 rn ,@sql2=@sql2+'@'+@ic+'='''',' rn ,@sql3='select @'+@ic+'=@'+@ic+'+a from # where gid='+@ic rn +char(13)+@sql3 rn ,@sql4=@sql4+'+@'+@ic rnrn select @sql1='declare '+left(@sql1,len(@sql1)-1)+char(13) rn ,@sql2=left(@sql2,len(@sql2)-1)+char(13) rn ,@sql3=left(@sql3,len(@sql3)-1) rn ,@sql4=substring(@sql4,2,8000) rnrn --执行 rn exec( @sql1+@sql2+@sql3+' rn exec('+@sqlhead+'+'+@sql4+'+'+@sqlend+')' rn ) )rnrn --删除临时表 rn drop table # rn[/code] 论坛

Struts里面DispatchAction 参数为空时如何处理

03-31

本人初学Struts,最近学做一个小项目。遇到DispatchAction参数为空的问题,不知道如何处理,求助于诸位大虾rnrn访问:http://localhost:8080/user.do?action=list时能正常转向相应页面,但是输入:http://localhost:8080/user.do时抱错:Request[/user] does not contain handler parameter named 'action'. This may be caused by whitespace in the label text.rnrnrn我的UserAction类大致是这样的结构:rnrnpackage com.pq.struts.action;rnrnimport javax.servlet.http.HttpServletRequest;rnimport javax.servlet.http.HttpServletResponse;rnimport javax.servlet.http.HttpSession;rnimport org.apache.struts.action.ActionForm;rnimport org.apache.struts.action.ActionForward;rnimport org.apache.struts.action.ActionMapping;rnimport org.apache.struts.actions.DispatchAction;rnimport org.apache.struts.action.ActionError;rnimport org.apache.struts.action.ActionErrors;rnimport java.util.ArrayList;rnimport java.util.List;rnrnimport com.pq.model.UserBean;rnimport com.pq.struts.form.UserForm;rnrn/*rn * 用户模块Actionrn * 2008.02.16rn */rnpublic class UserAction extends DispatchAction rnrn /*rn * 执行:/user.do?action=listrn * 作用:列出所有用户,然后转到页面:/UserList.jsprn */rn public ActionForward list(ActionMapping mapping, ActionForm form,rn HttpServletRequest request, HttpServletResponse response) rn rn UserForm uf = (UserForm) form;rn UserBean ub=new UserBean();rn List userList=ub.listAllUsers();//列出所有用户rn request.setAttribute("userList", userList); rn return mapping.findForward("UserList");rn rn rn //其他方法……rnrn 论坛

没有更多推荐了,返回首页