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

GetInt32(0); C#有关问题

2011-12-12 
GetInt32(0) C#问题StringstrCountselectcount(1)from( +strSql+)aintiCount0SqlCommandcmdCount

GetInt32(0); C#问题
String   strCount   =   "select   count(1)     from   ( "   +   strSql   +   ")   a   ";

                int   iCount   =   0;
                SqlCommand   cmdCount   =   new   SqlCommand(strSql,conn);
                dtr   =   cmdCount.ExecuteReader();
                if   (dtr.Read())
                {

                        iCount   =   dtr.GetInt32(0);此处老是提示指定的转换无效,我的数据库是SQLserver

                }

[解决办法]
select count(1) from ( " + strSql + ") a
是不是字段的值是null


*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)

最新版本:20070212

http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
[解决办法]
iCount = Convert.ToInt32(dtr.GetInt32(0).toString());
[解决办法]
object oo = dtr[0];
看看这里是值是多少.
[解决办法]
if (dtr.Read())
{

Response.Write(dtr[1].ToString());

}
[解决办法]
使用DataReader时。注意

if (dtr.Read())
{

}
[解决办法]
iCount = dtr.GetInt32(0);此处老是提示指定的转换无效,我的数据库是SQLserver

那是因为的第一列的数据类型不符。

热点排行