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
3
  • Welcome to StackOverflow: if you post code, XML or data samples, please highlight those lines in the text editor and click on the "code samples" button ( { } ) on the editor toolbar to nicely format and syntax highlight it! Commented May 4, 2012 at 5:23
  • 1
    Also: can you explain in normal words what you're trying to do, and where you're having problems?? Just throwing a long listing of code at us is not very helpful.... Commented May 4, 2012 at 5:23
  • There's no error to it but sql could not be updated. Commented May 4, 2012 at 5:52

2 Answers 2

1

What type of database are you using? Do you commit the changes to the database?

[Update (from discussion below)] It appears that VB automatically commits all commands unless you explicitly tell it not to, so that's not the problem.

[Update 2] My working theory is that the database is configured incorrectly, as in ExecuteNonQuery() Not Working

Another possibly explaination could be this: http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/dbbf8025-9f53-4862-8705-62a106fe2114

Sign up to request clarification or add additional context in comments.

13 Comments

I was trying to say what Bryan Moyles said below, but I'm not very familiar with the language you're using so I was too vague. I apologize.
Its okay. Thanks though. Im a lousy programmer.
It would seem that commiting the change isn't your problem. How strange... I'll keep digging a bit and let you know if I find anything. (source: forums.asp.net/t/948152.aspx/1)
I just looked up the API of ExecuteNonQuery(). Can you capture the value it returns and let us know what it is? (api: msdn.microsoft.com/en-us/library/…)
Public Sub CreateCommand(ByVal queryString As String, _ ByVal connectionString As String) Using connection As New SqlConnection(connectionString) Dim command As New SqlCommand(queryString, connection) command.Connection.Open() command.ExecuteNonQuery() End Using End Sub this? where shld i put them?
|
0

My suggestion would be to try running sqlCommand.Commit(), this "should" stash any changes you have made on the database, into the actual database. Please note, my actual "command" might be off, but the idea is there. If you can commit on the sql command, try committing on the connection level.

2 Comments

Right below the part in your code where you do sqlCommand.ExecuteNonQuery(), try running sqlCommand.Commit(). If there's an error, please let me know what it is :)
'Commit' is not a member of 'System.Data.SqlClient.SqlCommand'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.