我现在是做一个高级查询功能的,里面有个查找是说当余额小于某个值的时候,查找出来的数据如果在Balance.Text 没有输入任何东西的时候,会报错,即当Balance.Text 为空的时候,无法取得数值啊,这个应该要怎么处理?要对 float balance = (float)Convert.ToSingle(Balance.Text); 加以判断吗?怎么添加判断?各位帮帮忙啊,谢谢了
protected void searchbtn_Click(object sender, EventArgs e)
{ string rank = ddlUser.SelectedValue;
string usertype = ddlUsertype.SelectedValue;
string paytype = ddlPaytype.SelectedValue;
string username = userName.Text;
string companyname = companyName.Text;
float balance = (float)Convert.ToSingle(Balance.Text); string strSql = @"SELECT * FROM Userinfo WHERE 1=1 ";
if (rank != "--请选择--")
strSql += @" and Rank like '%" + rank + "%' ";
if (usertype != "--请选择--")
strSql += @" and Usertype like '%" + usertype + "%' ";
if (paytype != "--请选择--")
strSql += @" and Paytype like '%" + paytype + "%' ";
if(companyname !="")
strSql += @" and Companyname like '%" + companyname + "%' ";
if(username !="")
strSql += @" and Username like '%" + username + "%' ";
if (Balance.Text != "")
strSql += @" and Balance < " + balance + "";
gvUser.DataSource = DBUser.getDs(strSql, "Userinfo");
gvUser.DataBind();
DBUser.clear(); }
解决方案 »
- 请熟悉Webservice的高手指教
- Server-u架设FTP后的访问问题
- profile判断用户不同的问题
- ----------------------------正则表达式高手 ---------> 请
- 一般.net程序中使用什么orm框架,并请评价一下grove orm
- 如何将ASPX页面中的代码写如后置的CS文件中?
- 急!不知道怎么解决
- 如何用替换数据 (初级问题)
- 如何在微软中国社区得到积分 ?进入http://www.microsoft.com/china/community/default.mspx 哪个板块 ???
- 讨论:在asp.net里用哪种数据库连接方法比较好?
- Repeater ItemDataBound 事件无法触发
- 关于GridView中如何传参数的过程
{ string rank = ddlUser.SelectedValue;
string usertype = ddlUsertype.SelectedValue;
string paytype = ddlPaytype.SelectedValue;
string username = userName.Text;
string companyname = companyName.Text;
if(Balance.Text!=null||Balance.Text!="")
{
float balance = (float)Convert.ToSingle(Balance.Text);
string strSql = @"SELECT * FROM Userinfo WHERE 1=1 ";
if (rank != "--请选择--")
strSql += @" and Rank like '%" + rank + "%' ";
if (usertype != "--请选择--")
strSql += @" and Usertype like '%" + usertype + "%' ";
if (paytype != "--请选择--")
strSql += @" and Paytype like '%" + paytype + "%' ";
if(companyname !="")
strSql += @" and Companyname like '%" + companyname + "%' ";
if(username !="")
strSql += @" and Username like '%" + username + "%' ";
if (Balance.Text != "")
strSql += @" and Balance < " + balance + "";
gvUser.DataSource = DBUser.getDs(strSql, "Userinfo");
gvUser.DataBind();
DBUser.clear();
}
else
{
Response.Write("请输入值");
} }
float balance;
if (Balance.Text != "" && float.TryParse(Balance.Text,out balance)==true)
{
strSql += @" and Balance < " + balance + "";
}