解决:数据类型 text 和 varchar 在 equal to 运算符中不兼容

vs2008,gridview,sqldatasource
解决方法:

在gridview中,配制数据源,
设其为指定自定义的sql语句或存储过程,不选指定来自表或视图
下一步,
选update标签,
在系统自动产生的sql语句中,找到大字段所在的部位,形如:
UPDATE [T1] SET [f1] = @f1, [f2] = @f2, [f3] = @f3, [f4] = @f4 WHERE [id] = @original_id AND (([f1] = @original_f1) OR ([f1] IS NULL AND @original_f1 IS NULL)) AND (([f2] = @original_f2) OR ([f2] IS NULL AND @original_f2 IS NULL)) AND (([f3] = @original_f3) OR ([f3] IS NULL AND @original_f3 IS NULL)) AND (([4] = @original_f4) )

其中,f4为大字段
改为:

UPDATE [T1] SET [f1] = @f1, [f2] = @f2, [f3] = @f3, [f4] = @f4 WHERE [id] = @original_id AND (([f1] = @original_f1) OR ([f1] IS NULL AND @original_f1 IS NULL)) AND (([f2] = @original_f2) OR ([f2] IS NULL AND @original_f2 IS NULL)) AND (([f3] = @original_f3) OR ([f3] IS NULL AND @original_f3 IS NULL)) AND ((convert(nvarchar,[f4]) = @original_f4) )

注意使用了convert(新类型,原数据)函数
完美解决问题。
这个方法,在msdn上也很难找到。

by frank

你可能感兴趣的:(sql,null,存储)