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语句错误,到底错哪了???哪位大哥指正下,不胜感激!!!在线等答案……
不好意思,把 & 改成 + ,刚才忘了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.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”的转换无效。”)都不行啊,我也试过多次都错,究竟是为什么呢???
如果没有记录自然是0,还有*最好用你表的主键替换
感觉你有必要优化自己的查询语句了....
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)
哦,补充说明一下,其实我是要将一个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);