0
Protected Sub dgResult_ItemCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgResult.ItemCommand

If strErr = "" Then
Dim ddl As DropDownList = CType(e.Item.FindControl("ddlClassificationType"), DropDownList)

Dim defaultValue As Boolean = ddl.SelectedItem.Text.Contains("*")

Dim originalValue As String = String.Empty

If defaultValue = False Then

'update AppDetail

strErr = appDetailDBA.UpdateAppDetail(appCode, subCode, ddl.SelectedValue, Today.Date)

End If

   If strErr = "" Then

 lblError.Text = msgClass.successMsg(subCodeName, "1")

        Else

            lblError.Text = msgClass.ErrorMsg(subCodeName, "1")

        End If

        dgResult.DataSource = appDetailDBA.getDataClassification(empID, txtSearch.Text)

    dgResult.DataBind()

    End Sub



Function UpdateAppDetail(ByVal appCode As String, ByVal subCode As String, ByVal classType As String, ByVal classEffDte As String)


Dim strErr As String = ""
        Dim con As New SqlConnection(kiosk_loginConnStr)
        con.Open()

        Try
            Dim sqlCommand As SqlCommand = con.CreateCommand()
            Dim sql As String = "Update AppDetail SET ClassificationType = '" + classType + "', ClassificationEffDate = '" + classEffDte + "' WHERE AppCode = '" + appCode + "'" & _
                              " AND SubCode = '" + subCode + "'"

            sqlCommand.CommandText = sql
            sqlCommand.ExecuteNonQuery()
        Catch ex As Exception
            strErr = ex.Message
        Finally
            con.Close()
        End Try

        Return strErr
    End Function
4

2 回答 2

1

您使用的是什么类型的数据库?您是否将更改提交到数据库?

[更新(来自下面的讨论)] 似乎 VB 会自动提交所有命令,除非您明确告诉它不要这样做,所以这不是问题。

[更新 2] 我的工作原理是数据库配置不正确,如ExecuteNonQuery() Not Working

另一个可能的解释是:http ://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/dbbf8025-9f53-4862-8705-62a106fe2114

于 2012-05-04T04:17:00.563 回答
0

我的建议是尝试运行 sqlCommand.Commit(),这“应该”将您对数据库所做的任何更改存储到实际数据库中。请注意,我的实际“命令”可能已关闭,但想法就在那里。如果您可以在 sql 命令上提交,请尝试在连接级别上提交。

于 2012-05-04T04:22:21.573 回答