Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Guys,

I am creating a program in Visual Studio using vb. I have a database in access 2013, I have a row of data for a client with a notes column, I want to be able to add information to the notes column, go away, come back and add more information without loosing the information i already have. I'm using a UPDATE statement but cant get it to work, your help is much appreciated

Here's my code for the UPDATE STATEMENT:

VB
Dim cn As New OleDbConnection
        cn.ConnectionString = My.Settings.ChiChiEmporiumConnectionString
        Dim cmd As New OleDbCommand
        cmd.CommandText = ("UPDATE Client SET Notes = '" + vbNewLine + ItemIDTextBox.Text + "-" + Transaction_DateDateTimePicker.Value + "' WHERE ([Membership Number] = '" + Membership_NumberTextBox.Text + "')")
        cmd.Connection = cn

        cn.Open()
        cmd.ExecuteNonQuery()
Posted
Updated 24-Oct-14 16:29pm
v3
Comments
DamithSL 24-Oct-14 22:28pm    
update question with your code
Jonesy1394 24-Oct-14 22:30pm    
Have done :)

1 solution

When appending text, use following syntax

SQL
update
  tablename
set
  fieldname = convert(nvarchar(max),fieldname) + 'appended string'
where 
  fieldname2 = value2


or if you have old text and newly added text in one string. ( also you better use parameters)
VB
cmd.CommandText = "update Client set  Notes = ? where   [Membership Number]= ?"
cmd.Parameters.AddWithValue("@param1", combinedText)
cmd.Parameters.AddWithValue("@param2", Membership_NumberTextBox.Text)
 
Share this answer
 
v2
Comments
Jonesy1394 24-Oct-14 22:47pm    
Right having used your second lot of code, all that happened was what normally happens the old information was replaced. Gah! Am I missing something?

cmd.CommandText = ("UPDATE Client SET Notes = ? WHERE [Membership Number] = ?")
cmd.Parameters.AddWithValue("@param1", ItemIDTextBox.Text + "-" + Transaction_DateDateTimePicker.Value)
cmd.Parameters.AddWithValue("@param2", Membership_NumberTextBox.Text)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900