UPDATE语句不更新DB

时间:2012-05-04 04:11:59

标签: sql-update

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

2 个答案:

答案 0 :(得分:1)

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

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

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

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

答案 1 :(得分:0)

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