Question Updating a memo field

thirteentwenty

Well-known member
Joined
Oct 9, 2008
Messages
80
Location
Honolulu
Programming Experience
Beginner
OK, I was really hoping that I could figure this one out on my own, but alas I throw in the towel and return for more assitance...

What I'm trying to do: Update a memo field, I'm using the below code:

VB.NET:
   Public Function addNotes()
        ' Add Notes
        Dim notes As String = frm_invoices.txt_inv_notes.Text

        ' Invoice functions
        Dim strAddNotes As String
        Dim cmdAddNotes As New OleDb.OleDbCommand
        Dim chkAddNotes As Integer
        ' strInvoiceSetup = "INSERT INTO [Transaction Header]([Tax Rate:]) VALUES (TaxRate)"
        If notes <> "" Then
            strAddNotes = "UPDATE [Transaction Header] SET [Notes] = notes WHERE ID=" & frm_invoices.txt_inv_transID.Text & ""
            MessageBox.Show("Trans ID: " & frm_invoices.txt_inv_transID.Text & vbCrLf & "Notes: " & notes, "If statement")
        Else
            Return MessageBox.Show("Exiting Function", "", MessageBoxButtons.OK)
            Exit Function
        End If

        Try

            HandleConnection(con)

            ' Update Invoice with Notes Field
            cmdAddNotes.CommandText = strAddNotes
            cmdAddNotes.CommandType = CommandType.Text
            cmdAddNotes.Parameters.AddWithValue("Notes", notes)

            cmdAddNotes.Connection = con
            chkAddNotes = cmdAddNotes.ExecuteNonQuery()

            ' ERROR CONTROL
            ' Uncomment below code to see if update is successful
            If Not chkAddNotes = 0 Then
                MessageBox.Show("Notes Added Successfully", "ExecuteNonQuery Error", MessageBoxButtons.OK)
                Return True
            Else
                MessageBox.Show("Update Failed", "ExecuteNonQuery Error", MessageBoxButtons.OK)
                Return False
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message, "Update Error Report", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return ""
            Exit Function
        Finally
            cmdAddNotes.Parameters.Clear()
        End Try

        Return ""
    End Function

The problem: Nothing, well nothing updates, what ever is in the textbox does not go into the memofield... but the function does not produce any errors

What I've tried, I have in another function, an INSERT, and have placed the notes in there with the expected results, the notes were inserted...

So, it would seem to me that the underlying isssue is with this update command (I' have a functioning update else where) but it seems that I cannot update this table specifically... (I've tried to update other columns as well)

Any suggestions would be much appreciated...

oh yes and I did try the DW2 link *wink*
 
Last edited:
oh yes and I did try the DW2 link *wink*

Given that you have written this massive, 20 year old security flaw into your code:

"UPDATE [Transaction Header] SET [Notes] = notes WHERE ID=" & frm_invoices.txt_inv_transID.Text & ""

I doubt that you have followed DW2.. I don't mean to sound harsh, but you won't find a section called "How to write crap, out-of-date, non-OO code that is prone to SQL Injection Attacks in order to update a Memo field in Access".. people (newbies, oldies) who write code like this need a good kick into modern code writing so I hope you don't mind if I deliver that (extra discussion: read the PQ link in my signature) with a bit of a slap. Read PQ.

In DW2 you will find lots of sections that deal with writing proper, good, modern data access code. FOllow them and update ALL your techniques. Along the way, the DS designer will make code that properly updates a memo for you.. Youre getting concerned with problems that wouldnt occur if you were using the designer to build your DAL
 

Latest posts

Back
Top