关于用DataTable.Select()方法出现“无法在 System.String 和 System.Int32 上执行“=”操作。”错误的原因
来源:互联网 发布:图像尺寸测量软件 编辑:程序博客网 时间:2024/06/07 13:01
错误代码如下:
DataRow[] drxm = dtXSHDList[2].Select("yxsh='" + dtXSHDList[0].Rows[row1]["xsbh"].ToString() + "'" + " and zydm= " + dtzy.Rows[row2]["zydm"].ToString());
刚开始百思不得其解,因为zydm是varchar类型,而右边也.ToString()了,哪来的Int?后来网上看了一下,说DataTable.Select()会自动转化类型。zydm虽然是varchar,但是基本上都是数字组成的,于是我怀疑zydm字段被转化成了int,遂有了:
DataRow[] drxm = dtXSHDList[2].Select("yxsh='" + dtXSHDList[0].Rows[row1]["xsbh"].ToString() + "'" + " and convert(zydm,'System.String')= " + dtzy.Rows[row2]["zydm"].ToString());
然并卵。
这时候看了 System.String 和 System.Int32的位置,应该还是后面的错误。然后想到sql语句里面非int类型要加单引号。
于是:
DataRow[] drxm = dtXSHDList[2].Select("yxsh='" + dtXSHDList[0].Rows[row1]["xsbh"].ToString() + "'" + " and zydm='" + dtzy.Rows[row2]["zydm"].ToString() + "'");
问题解决。
- 关于用DataTable.Select()方法出现“无法在 System.String 和 System.Int32 上执行“=”操作。”错误的原因
- 无法在 System.DateTime 和 System.String 上执行“>”操作。
- 无法在 System.Guid 和 System.String 上执行“=”操作
- Linq集合查询出现无法将类型为“System.Int32”的对象强制转换为类型“System.String”异常
- 关于MVC中无法将类型为“System.Int32”的对象强制转换为类型“System.String”的问题。
- C# 类型“System.String”的对象无法转换为类型“System.Int32”
- 无法将类型为“System.Int32”的对象强制转换为类型“System.String”
- 在Window2003上执行System.Diagnostics.Process.GetProcessesByName等方法失败的原因
- 将DataTable转换为List<T>对象遇到问题:类型“System.Int64”的对象无法转换为类型“System.Int32”
- LINQ to Entities 不识别方法“Int32 ToInt32(System.String) 或 “Int32 Parse(System.String)”
- EF 错误LINQ to Entities 不识别方法“Int32 ToInt32(System.String)
- ASP.NET.MVC异常--无法将类型为System.Int32的对象强制转换为类型System.String
- LINQ to Entities 不识别方法“Int32 ToInt32(System.String)
- LINQ to Entities 不识别方法“Int32 ToInt32(System.String)”,因此该方法无法转换为存储表达式
- 使用PropertyGrid是出现无法找到System.String上的构造函数的解决方法
- 关于在DataTable中执行DataTable.Select("条件")返回DataTable的解决方法
- 关于在 xmlSPY 出现的错误 DOCTYPE-EXternalID的名称必须既是SYSTEM 又是PUBLIC?
- 在Share Point 2010中,如何使用 in 语句?并且解决Boolean Contains[Int32](System.Collections.Generic.IEnumerable`1[System.Int32], Int32)的问题。
- Javascript中的apply、call、bind
- 关于STM32中CAN中断的使用
- Quartz-2D绘图之图形上下文详解
- homerHEVC代码阅读(36)——环路滤波(2)SAO
- java.lang.IllegalStateException: FragmentManager is already executing transactions
- 关于用DataTable.Select()方法出现“无法在 System.String 和 System.Int32 上执行“=”操作。”错误的原因
- java中Arrays.parallelSort和Arrays.sort性能对比
- 关于性能测试的那些事
- Quartz-2D绘图之路径(Paths)详解
- 第三章:Java 环境你必须知道的一切
- 本地连接IP切换bat命令
- Java性能测试的四项原则【转】
- linux下svn常用命令
- 根据时间戳返回时间间隔