Dim SqlStr As String            SqlStr = "select isnull(count(*),0) from u_ly where to_lyr=" & Integer.Parse(HttpContext.Current.User.Identity.Name.ToString()) & " and viewtag='0'"            Dr = SqlObj.ExecuteReader(SqlStr)错误提示为: 输入字符串的格式不正确,为SQL语句错误,到底错哪了???哪位大哥指正下,不胜感激!!!在线等答案……

解决方案 »

  1.   

    Dim SqlStr As String             SqlStr = "select isnull(count(*),0) from u_ly where to_lyr='" & Integer.Parse(HttpContext.Current.User.Identity.Name.ToString()) & "' and viewtag='0'" 
      

  2.   

    vb和c#基本一样String SqlStr="";             SqlStr = "select isnull(count(*),0) from u_ly where to_lyr='" & Integer.Parse(HttpContext.Current.User.Identity.Name.ToString()) & "' and viewtag='0'" 这是c#写法,和vb基本一样
      

  3.   


    不好意思,把 & 改成 + ,刚才忘了String SqlStr="";             SqlStr = "select isnull(count(*),0) from u_ly where to_lyr='" + Integer.Parse(HttpContext.Current.User.Identity.Name.ToString()) + "' and viewtag='0'" 
      

  4.   

    where 条件如果是字符串应该用''将字符串包含
    否则不成功
      

  5.   


    哦,补充说明一下,其实我是要将一个C#例子改为VB.NET,在数据库中字段  to_lyr 为浏览人数int类型, viewtag 默认值为'0' ,char类型    在C#中原句为  
                  String SqlStr;
                SqlStr = "select isnull(count(*),0) from u_ly where to_lyr=" + int.Parse(HttpContext.Current.User.Identity.Name.ToString()) + " and viewtag='0'";
                 Dr=SqlObj.ExecuteReader(SqlStr);
             程序不存在错误,但改成Vb.net后 SqlStr = "select isnull(count(*),0) from u_ly where to_lyr='" & Integer.Parse(HttpContext.Current.User.Identity.Name.ToString()) & "' and viewtag='0'" (错误为“输入字符串的格式不正确。”)而 SqlStr = "select isnull(count(*),0) from u_ly where to_lyr='" + Integer.Parse(HttpContext.Current.User.Identity.Name.ToString()) + "' and viewtag='0'" (错误则为“从字符串“select isnull(count(*),0) from u”到类型“Double”的转换无效。”)都不行啊,我也试过多次都错,究竟是为什么呢???
      

  6.   

    谢谢你回答,但我试过了,还是不对的前者(错误为“输入字符串的格式不正确。”),后面的(错误则为“从字符串“select isnull(count(*),0) from u”到类型“Double”的转换无效。”),其实这种写法'" & Integer.Parse(HttpContext.Current.User.Identity.Name.ToString()) & "' 我以前经常用到,按理说这种格式正确才对啊,怎么现在不行了???郁闷死了
      

  7.   

    isnull(count(*),0)  isnull有必要写吗
    如果没有记录自然是0,还有*最好用你表的主键替换
    感觉你有必要优化自己的查询语句了....
      

  8.   


    Dim SqlStr As String             SqlStr = "select isnull(count(*),0) from u_ly where to_lyr=" & HttpContext.Current.User.Identity.Name.ToString() & " and viewtag='0'"            Dr = SqlObj.ExecuteReader(SqlStr) 
      

  9.   

     to_lyr这个是什么类型的,如果是字符串,就要用''引起来
      

  10.   


    哦,补充说明一下,其实我是要将一个C#例子改为VB.NET,在数据库中字段  to_lyr 为浏览人数int类型, viewtag 默认值为'0' ,char类型    在C#中原句为  
                  String SqlStr; 
                SqlStr = "select isnull(count(*),0) from u_ly where to_lyr=" + int.Parse(HttpContext.Current.User.Identity.Name.ToString()) + " and viewtag='0'"; 
                Dr=SqlObj.ExecuteReader(SqlStr); 
      

  11.   

          SqlStr = "select isnull(count(*),0) from u_ly where to_lyr=" & Integer.Parse(HttpContext.Current.User.Identity.Name.ToString()) & " and viewtag='0' "楼主你的这个HttpContext.Current.User.Identity.Name.ToString()要是是字符的话就不能转换成整型的了,比如“Zhao”你怎么可能把它转换成整型