1/2页12 跳转到查看:1395
发新话题 回复该主题

好像又出现了如果字段给了一个空值不更新的BUG。

好像又出现了如果字段给了一个空值不更新的BUG。

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim CommId As String = q("CommId")
        Dim Comment As New Comment
        Dim conditionValue As New NameValueCollection
        conditionValue("id") = CommId
        If (ReContent_Input.Text = "") Then
            Comment.Entity.Rec
        Else
            Comment.Entity.Recontent = ReContent_Input.Text
        End If
        If Comment.Update(conditionValue) > 0 Then
            Tools.JsExe("更新成功!", "WebComment.aspx", 2)
        Else
            Tools.Alert("更新失败!", 1)
        End If
    End Sub

上面代码中当Recontent_Input.text出现空值时则不更新且出现错误:
<ErrorLog Date="2009-05-25">
  <ErrorTime Value="4:24">
    <Method>ExecuteNonQuery</Method>
    <Parames>[fieldName=System.Collections.Specialized.NameValueCollection;fieldValue=;strSql=System.Collections.ArrayList;conditionValue=;tableName=System.Collections.ArrayList;dbAction= where id=@id ;]</Parames>
    <ErrorMsg>关键字 'where' 附近有语法错误。</ErrorMsg>
    <Trace>  在 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
  在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
  在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
  在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
  在 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
  在 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
  在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
  在 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
  在 System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
  在 Winson.Framework.DBProviders.DBProvider.ExecuteNonQuery(DBAction dbAction, String tableName, String strSql, ArrayList fieldName, ArrayList fieldValue, NameValueCollection conditionValue) 位置 g:\个人设计\CodeItem\Winson.Framework\DBProviders\DBProvider.cs:行号 110</Trace>
  </ErrorTime>

TOP

 

你这个字段是什么类型的数据?调试一下,看看最终生成的SQL语句是什么?
随风飘飘天地任逍遥!
代码部落
http://winsonet.cnblogs.com

TOP

 

最终生成的只有where id=@id,前面没有任何东西了。

TOP

 

我是说你用调试断点的方式,看看最终执行到此的完整的SQL语句,还有你的ID的值是什么等
随风飘飘天地任逍遥!
代码部落
http://winsonet.cnblogs.com

TOP

 

我写的就是最终的完整SQL语句来着的,我也在奇怪为什么前面那一段都没有的。你可以自己随便一个测试下,只是要给空字段的都是这个样子。
id的值就是数字来着的。

TOP

 

你指的空字段是指这个ID为空吗?空是指在赋值时不设置此字段还是指直接给一个空格啊?请把问题说清楚些吧
随风飘飘天地任逍遥!
代码部落
http://winsonet.cnblogs.com

TOP

 

算了,我不说了,我已经说得很清楚了,我写的就是最终测试得到的完整SQL语句,前面一段根本都没有,而且这个与条件扯不上关系吧?再者你自己随便搞个测试下就知道了。

TOP

 

我所理解你说的空值就是不设置此字段的值,这个在正常情况上都没问题的,这种情况下我都不知道试过多少次了,如果你连自己的问题都表达不清楚,那我也没法帮你了,而且我也说过很多次了,因为每个人的情况都可能不同,所以最好能自己先调试一下,做程序员要学会自己调试程序,像这些问题,只要调试一下就很容易就找到原因
随风飘飘天地任逍遥!
代码部落
http://winsonet.cnblogs.com

TOP

 

case 0:
                             if (Id > 0)
                                 return "Id";
                             else
                                 return null;
                         case 1:
                             if(Title != null && Title.Length > 0)
                                 return "Title";
                             else
                                 return null;
                         case 2:
                             if(Ccontent != null && Ccontent.Length > 0)
                                 return "Ccontent";
                             else
                                 return null;
                         case 3:
                             if(Username != null && Username.Length > 0)
                                 return "Username";
                             else
                                 return null;
                         case 4:
                             if(Usserip != null && Usserip.Length > 0)
                                 return "Usserip";
                             else
                                 return null;
                         case 5:
                             //if(Recontent != null && Recontent.Length > 0)
                            if (Recontent != null)
                                 return "Recontent";
                             else
                                 return null;
                         case 6:
                             if(_languangs != 0 || _languangsSetValue)
                                 return "Languangs";
                             else
                                 return null;
                         case 7:
                             if(Email != null && Email.Length > 0)
                                 return "Email";
                             else
                                 return null;
                         case 8:
                             if(Adddate != DateTime.MaxValue && Adddate != DateTime.MinValue)
                                 return "Adddate";
                             else
                                 return null;
                        default:
                            return null;       
像这么一段我就不太明白了,如果给文本字段赋一个空字段的时候会不会因为Length=0而返回null,既然返回null,那么如何会在这里填充值的?
/// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="ds">实体</param>       
        /// <param name="conditionValue">
        ///    条件参数,有以下2种:
        ///    1.如键名为"sql",则为完整的自定义sql语句
        ///    2.如键名为"where",则为自定义条件(已包括where);           
        ///    </param>
        /// <returns>影响记录数</returns>
        public int Update(CommentDS ds, NameValueCollection conditionValue)
        {
            try
            {
                fieldName = new ArrayList();
                fieldValue = new ArrayList();
                for (int i = 0; i < ds.Count; i++)
                {
                    if (ds[i, 1, 0] != null)
                    {
                        //MessageBox.ShowBack(ds[i, 1, 0].ToString());
                        fieldName.Add(ds[i, 1, 0]);
                        fieldValue.Add(ds[i, 0, 0]);
                    }
                }
                return DBManage.ExecuteNonQuery(DBAction.Update, _tableName, fieldName, fieldValue, conditionValue);
            }
            catch (Exception e)
            {
                LogManage.OutputErrLog(e, new Object[] { ds, conditionValue });
                return 0;
            }
        }

TOP

 

如果将这个length的判断去掉后就可以正常执行?这就是所谓的没有问题?

TOP

 
1/2页12 跳转到
发表新主题 回复该主题