Как написать инструкцию SQL update для richtextbox?
Hello all. Am new to VB.Net and seeking some assistance. With some help from the internet, I managed to save a richtext document to SQL server and then access for viewing. How do I write an update statement to save it back to SQL? Thanks in advance.
Что я уже пробовал:
Dim cmd As New SqlCommand("Select richtext from tablename", con) Try rtbdoc.SaveFile("Test.rtf") Dim Stream = New FileStream("Test.rtf", FileMode.Append, FileAccess.ReadWrite) Dim size As Integer = Convert.ToInt32(Stream.Length) Dim rtf As [Byte]() = New [Byte](size - 1) {} Stream.Read(rtf, 0, size) Dim paramRTF As New SqlParameter("@rtf", SqlDbType.VarBinary, rtf.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, rtf) cmd.CommandText = "Update table SET firstname = '" & txtfirstname.Text & "', lastname = '" & txtlastname.Text & "' richtext = @rtf where id = @id" If con.State = ConnectionState.Open Then con.Close() con.Open() cmd.Parameters.Add("@id", SqlDbType.Int).Value = txtid.Text cmd.Parameters.Add(paramRTF) 'cmd.ExecuteNonQuery( cmd.ExecuteNonQuery() MessageBox.Show("File Updated Successfully") clear() Catch ex As Exception MsgBox("Error updating record!", MsgBoxStyle.Critical) clear() Finally If Stream.Null IsNot Nothing Then Stream.Null.Close() End If End Try