当前位置: 代码迷 >> ASP.NET >> Convert.ToInt32的转化有关问题
  详细解决方案

Convert.ToInt32的转化有关问题

热度:1820   发布时间:2013-02-25 00:00:00.0
Convert.ToInt32的转化问题
HTML code
SqlDataBase ThisB = new SqlDataBase();        string CheckSql = "select count(*) from UserList where UserName = '" + UserName + "' and PassWord = '" + PassWord + "'";        int ThisNum = Convert.ToInt32(ThisB.ReturnSQL(CheckSql));


这里老是说:System.FormatException: 输入字符串的格式不正确。

出错就错在:int ThisNum = Convert.ToInt32(ThisB.ReturnSQL(CheckSql))这行,请问该怎么处理,请高手指点下,我看到有人网上说这里输出下,可是我这个是在一个cs文件的类里,我该怎么输出,用response.write又说不允许使用。求教,求教,我是.net新手

------解决方案--------------------------------------------------------
你先看(ThisB.ReturnSQL(CheckSql))拿到的是什么
------解决方案--------------------------------------------------------
object ob=ThisB.ReturnSQL(CheckSql);
看看是什么
------解决方案--------------------------------------------------------
ThisB.ReturnSQL()方法的返回值有问题~
------解决方案--------------------------------------------------------
输入字符串的格式不正确 就看看输入的是什么呗,是不是不能转换成int
------解决方案--------------------------------------------------------
ReturnSQL返回的什么呀?
CheckSql不就是返回的count吗
------解决方案--------------------------------------------------------
SqlDataBase ThisB = new SqlDataBase();
tring CheckSql = "select count(*) from UserList where [UserName] = '" + UserName + "' and [PassWord] = '" + PassWord + "'";

System.Web.HttpContext.Current.Response.Write(ThisB.ReturnSQL(CheckSql)); //看是什么
//int ThisNum = Convert.ToInt32(ThisB.ReturnSQL(CheckSql));
------解决方案--------------------------------------------------------
int ThisNum = int.Parse(ThisB.ReturnSQL(CheckSql).ToString().Trim());



------解决方案--------------------------------------------------------
探讨

我把两个文件的代码都贴出来了,我就是看不来,这个ThisB.ReturnSQL(CheckSql)到底返回了什么,但数据库中,用select count(*)就算没记录也应该返回0,不应该是null的,是吧?
  相关解决方案