首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

Convert.ToInt32的转化有关问题

2012-03-27 
Convert.ToInt32的转化问题HTML codeSqlDataBase ThisB new SqlDataBase()string CheckSql select c

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的,是吧?

热点排行