在SqlDataSource控件的参数里,尽量用Type属性,少用DbType属性
就是要记住这句话,用Type属性,少用DbType属性,因为现在很多服务器没有安装.net frameworkk 3.5,如果用了DbType,会出现报错:
类型“System.Web.UI.WebControls.ControlParameter”不具有名为“DbType”的公共属性。
或者:
'System.Web.UI.WebControls.Parameter' does not have a public property named 'DbType'
我查不到原因,这里有一个帖子:
http://forums.asp.net/t/1286923.aspx
If you look closer at the error, it is telling you what is wrong. You are trying to access the database, but the error mentions a 'System.Web.UI.WebControls.Parameter' type. You should be using an IDataParameter or IDbDataParameter. (That's the interface that specialized classes implement, e.g., System.Data.SqlClient.SqlParameter implements both interfaces.)
Maybe there is a discrepancy between the datatype declared and how it is implemented at the host?
查了好多,都是说要就升级服务器到3.5 sp1,要就改用Type,程序员对服务器没有控制权,最好是用Type,不要用DbType了
就是,这是为什么呢?我的机器上装了vs.net2005、vs.net2008,我以为是因为DbType在System.Data.SqlClient.SqlParameter里满足两个接口,所以会出现在上下文菜单里,就是,小燕子的机器只有vs.net2005,没有装.net framework3.5,她的上下文菜单里,一样子有DbType属性
我一直更愿意用DbType的,因为我用的是MS SQL数据库,现在要记住换掉,要用.net自己的Type