数据仍然保存在零

时间:2016-05-03 08:02:23

标签: vb.net

在我的代码中,如果没有天数完成,数据将保存= 0.我希望它不会发生 在我的代码中,msg出现“完成时间和确认时间只能是正确的”但仍然是数据保存。我不希望它被保存!!

Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
        Try
            Dim i As Integer
            If gvBanckmark.Rows.Count > 0 Then
                For i = 0 To gvBanckmark.Rows.Count - 1
                    Dim lblBenchMarkID As Label = CType(gvBanckmark.Rows(i).FindControl("lblBenchMarkID"), Label)
                    Dim lblSubCategoryId As Label = CType(gvBanckmark.Rows(i).FindControl("lblSubCategoryId"), Label)
                    Dim ddlFrequencyTypeAcknowledge As DropDownList = CType(gvBanckmark.Rows(i).FindControl("ddlFrequencyTypeAcknowledge"), DropDownList)
                    Dim ddlFrequencyTypeComplete As DropDownList = CType(gvBanckmark.Rows(i).FindControl("ddlFrequencyTypeComplete"), DropDownList)
                    Dim txtTimeToAcknowledge As TextBox = CType(gvBanckmark.Rows(i).FindControl("txtTimeToAcknowledge"), TextBox)
                    Dim txtTimeToComplete As TextBox = CType(gvBanckmark.Rows(i).FindControl("txtTimeToComplete"), TextBox)

                    Dim objBenchMark As BO.BenchMark = New BO.BenchMark()
                    objBenchMark.BuildingID = Convert.ToInt32(ddlBuilding.SelectedValue)
                    objBenchMark.CategoryID = Convert.ToInt32(ddlCategory.SelectedValue)
                    objBenchMark.SubCategoryID = Convert.ToInt32(lblSubCategoryId.Text.ToString())
                    objBenchMark.FrequencyTypeToAcknowledge = ddlFrequencyTypeAcknowledge.SelectedValue.ToString()
                    objBenchMark.FrequencyTypeToComplete = ddlFrequencyTypeComplete.SelectedValue.ToString()
                    objBenchMark.TimeToAcknowledge = Convert.ToInt32(txtTimeToAcknowledge.Text.ToString())
                    objBenchMark.TimeToComplete = Convert.ToInt32(txtTimeToComplete.Text.ToString())

                    If lblBenchMarkID.Text.ToString() = 0 Then
                        objBenchMark.BenchMarkID = 0
                        objBenchMark.CreateByUserId = UserWrapper.GetCurrentUser().ContactID
                        BO.BenchMark.InsertBechMarkData(objBenchMark)
                    Else
                        objBenchMark.BenchMarkID = Convert.ToInt32(lblBenchMarkID.Text.ToString())
                        objBenchMark.ModifiedByUserId = UserWrapper.GetCurrentUser().ContactID
                        BO.BenchMark.UpdateBechMarkData(objBenchMark)
                    End If
                Next i
            End If
            lblError.Visible = True
            lblError.Text = "<a cssClass=""messageGood"">Benchmark data has been saved sucessfully.</a>"
        Catch ex As Exception
            lblError.Text = ex.Message
            lblError.Visible = True
        End Try
    End Sub 

1 个答案:

答案 0 :(得分:0)

您的数据未被保存,但正在显示告知您数据已保存的消息,尽管它已保存或未保存。

在if-end中移动这些行if:

lblError.Visible = True
lblError.Text = "<a cssClass=""messageGood"">Benchmark data has been saved sucessfully.</a>"