给变量赋值问题

litengfei001 2010-04-12 12:09:28
请教个问题啊 在给变量赋值的时候 如何判断是否为空

比如这样例子 string P_str_CartID = Session["UserID"].ToString();


string P_str_GoodsID = Request["GoodsID"];
DataSet ds = DB.reDs("select count(*) from tb_Cart where CartID=" + P_str_CartID + "and GoodsID=" + P_str_GoodsID);

如何判断UserID是否为空 是跳转到哪里 不为空继续执行代码


那位大哥大姐 指教下 加我 Q 412122406
...全文
65 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
fxsy6669 2010-04-12
  • 打赏
  • 举报
回复
if(Session["UserID"] != null && Session["UserID"].ToString() != "")
{
Response.Redirect("a.aspx");
}
else
{
Response.Redirect("b.aspx");
}
Adechen 2010-04-12
  • 打赏
  • 举报
回复
if(Session["UserID"]!=null)
{

}
else
{

}
youqi6597480 2010-04-12
  • 打赏
  • 举报
回复
顶楼上。。。。
txj_0113 2010-04-12
  • 打赏
  • 举报
回复

以下方法可以试一下:
if(!page.ispostback)
{
if(!string.isnullorempty(Session["UserID"]))
{


}

}
ztingtingmck 2010-04-12
  • 打赏
  • 举报
回复
if(Session["UserID"] != null)
{
if(Session["UserID"].ToString()!="")
{
string P_str_CartID = Session["UserID"].ToString();


string P_str_GoodsID = Request["GoodsID"];
DataSet ds = DB.reDs("select count(*) from tb_Cart where CartID=" + P_str_CartID + "and GoodsID=" + P_str_GoodsID);

}
}
else
{
Response.Redirect("x.aspx");//链接到错误页面

}
baoxuetianxia 2010-04-12
  • 打赏
  • 举报
回复

if(Session["UserID"] != null)
{
if(Session["UserID"].ToString()!="")
{
string P_str_CartID = Session["UserID"].ToString();


string P_str_GoodsID = Request["GoodsID"];
DataSet ds = DB.reDs("select count(*) from tb_Cart where CartID=" + P_str_CartID + "and GoodsID=" + P_str_GoodsID);

}
}
else
{
Response.Redirect("x.aspx");//链接到错误页面

}



chen_ya_ping 2010-04-12
  • 打赏
  • 举报
回复
程序中进行if()判断不行吗?
Peter200694013 2010-04-12
  • 打赏
  • 举报
回复
if(Session["UserID"] == null)
{
Response.Redirect("x.aspx");
}
else
{
// your operation
}
wx8849 2010-04-12
  • 打赏
  • 举报
回复
if(Session["UserID"]!=null)
{
执行的代码
}
elec
{
要跳转的页面
}
litengfei001 2010-04-12
  • 打赏
  • 举报
回复
麻烦上面说的详细点好吗
criedshy 2010-04-12
  • 打赏
  • 举报
回复
if(Session["UserID"]!=null)
{

}
threenewbee 2010-04-12
  • 打赏
  • 举报
回复
也可以用 try { } catch { } 或者 if ( ) { } 包起来。
threenewbee 2010-04-12
  • 打赏
  • 举报
回复
string P_str_GoodsID = Request["GoodsID"] ?? "0";

62,041

社区成员

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

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

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

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