昨天,就在昨天俺将我的VS2005 专业版 换成了VS2005 Team Suite 。今天有问题发生啦!以前一个很简单的操作,今天竟然不行啦!就是我拖一个GridView 然后我配置数据源,和以前一样,选择数据连接,选择表(*)在高级里启用 生成(Insert,Update,Delete)和启用开放式并发。一切都和往常一样,可是运行的结果让我吃惊。 运行结果 可以排序,可以分页,可以选择,但是不能经行编辑的更新和删除。(以上几项均已启用)它给我的错误提示是不能比较或排序 text、ntext 和 image 数据类型,除非使用 IS NULL 或 LIKE 运算符。 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: 不能比较或排序 text、ntext 和 image 数据类型,除非使用 IS NULL 或 LIKE 运算符。Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  Stack Trace: 
[SqlException (0x80131904): 不能比较或排序 text、ntext 和 image 数据类型,除非使用 IS NULL 或 LIKE 运算符。]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +95
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +82
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +346
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +3430
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +186
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1139
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +334
   System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +407
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +149
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +493
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteDelete(IDictionary keys, IDictionary oldValues) +922
   System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) +176
   System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +914
   System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +1067
   System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +215
   System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +244
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3840 
后来我就换了个数据连接,换了个数据库。但是也不能经行 (删除 和 更新)操作。
这次它没有错误发生,就是数据显示无变化。像以上的两个数据库,在以前我用以上相同的操作是没有问题的。为什么换了个版本后会出现这样的问题呢?

解决方案 »

  1.   

    提示很明显,你进行删除的条件里有字段是text、ntext类型的,这样不能用 col='str'来查询的,要用like,或是charIndex
      

  2.   

    把text、ntext类型的改为varchar()类型就好了。
      

  3.   

    问下楼上的各位 text and ntext 的不能进行更新和删除吗?
      

  4.   

    我看啦下它的删除语句是下面这样的
    DELETE FROM [news] WHERE [Id] = @original_Id AND [Title] = @original_Title AND [Content] = @original_Content AND [PubTime] = @original_PubTime我把它改成这样就可以啦!
    DELETE FROM [news] WHERE [Id] = @original_Id
    不明白为什么以前可以不用这么做也行,怪郁闷的?
    各位是不是text or ntext 的字段语句要这么写啊
    ........... and [Title] like @original_Title  AND [Content] like @original_Content 如果是的话,为什么数据源配置的时候,当启用(Insert Update Delete)时它不会自己识别生成呢?
      

  5.   

    传说中的只需GridView And DataSource 不需写任何代码就能实现数据的显示和更新删除操作。
    我今天还真就不信啦!
    为什么当字段出现text or ntext or Image 类型时,我们还得这样做?

    DELETE FROM [news] WHERE [Id] = @original_Id AND [Title] = @original_Title AND [Content] = @original_Content AND [PubTime] = @original_PubTime
    改成
    DELETE FROM [news] WHERE [Id] = @original_Id AND [Title] like @original_Title  AND [Content] like @original_Content 
    还不是要改代码?
      

  6.   

    各位我把字段類型改成nvarchar 的也不行啊?他生成的Update Delte 語句里Where 里還得改成like 形式的(WHERE [Id] = @original_Id AND [Title] = @original_Title AND [Content] = @original_Content AND [PubTime] = @original_PubTime)‘其實有[Id] = @original_Id不就可以啦嘛! 我以前做的時候什么都沒有改都運行正常,用的是同一個數據庫。
    我是真的想知道是什么原因?哎!