如何通过vb.net将其他文本添加到数据库中的行 [英] How to add additional text to a row in database via vb.net
问题描述
嗨大家好,
我正在使用vb在Visual Studio中创建一个程序。我在访问2013中有一个数据库,我有一行数据用于带有注释列的客户端,我希望能够将信息添加到注释列,离开,返回并添加更多信息而不会丢失信息我已经有。我正在使用UPDATE语句,但无法使其工作,非常感谢您的帮助
这是我更新声明的代码:
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:
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()
推荐答案
附加文字时,请使用以下语法
When appending text, use following syntax
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)
cmd.CommandText = "update Client set Notes = ? where [Membership Number]= ?"
cmd.Parameters.AddWithValue("@param1", combinedText)
cmd.Parameters.AddWithValue("@param2", Membership_NumberTextBox.Text)
这篇关于如何通过vb.net将其他文本添加到数据库中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!