943,083 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 1845
  • VB.NET RSS
Dec 24th, 2009
0

rich textbox and ms sql

Expand Post »
i'm a beginner in vb.net

i just want to know if it is possible to store the formatting of a text to ms sql so that the next time i retrieve a record that i've already formatted, it will display the format that i did for that record.

if possible, how would i implement it in mssql?

thanks
Similar Threads
Reputation Points: 11
Solved Threads: 0
Junior Poster in Training
scias23 is offline Offline
69 posts
since Jan 2009
Dec 24th, 2009
0
Re: rich textbox and ms sql
Here is an example. This form has 2 RTF boxes and a button:
VB.NET Syntax (Toggle Plain Text)
  1. Imports System.Data.SqlClient
  2. Imports System.Text
  3.  
  4. Public Class frmRTF
  5.  
  6. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  7. Const RECORD_ID As Integer = 1000
  8.  
  9. Dim Sql As New List(Of String)
  10. Sql.Add("IF OBJECT_ID('tempdb..##RTF', 'U') IS NOT NULL DROP TABLE ##RTF")
  11. Sql.Add("Create Table ##RTF")
  12. Sql.Add("(")
  13. Sql.Add(" RecordId int PRIMARY KEY,")
  14. Sql.Add(" RTF nvarchar(max)")
  15. Sql.Add(")")
  16. Sql.Add("Insert Into ##RTF (RecordId, RTF) Values (@RecordId, @RTF)")
  17. Dim query As String = GetText(Sql)
  18.  
  19. Using conn As New SqlConnection("Data Source=apex2006sql;Initial Catalog=Scott;Integrated Security=True;")
  20. conn.Open()
  21. Using cmd As New SqlClient.SqlCommand(query, conn)
  22. cmd.Parameters.Add(New SqlParameter("@RecordId", SqlDbType.Int)).Value = RECORD_ID
  23. cmd.Parameters.Add(New SqlParameter("@RTF", SqlDbType.NVarChar)).Value = RichTextBox1.Rtf
  24. cmd.ExecuteNonQuery()
  25. End Using
  26.  
  27. 'I'm using a temp table so the connection has to be left open
  28.  
  29. query = "Select * From ##RTF Where RecordId = @RecordId"
  30. Using cmd As New SqlClient.SqlCommand(query, conn)
  31. cmd.Parameters.Add(New SqlParameter("@RecordId", SqlDbType.Int)).Value = RECORD_ID
  32. Using dr As SqlDataReader = cmd.ExecuteReader()
  33. Using dt As New DataTable()
  34. dt.Load(dr)
  35. RichTextBox2.Rtf = Convert.ToString(dt.Rows(0)("RTF"))
  36. End Using
  37. End Using
  38. End Using
  39. conn.Close()
  40. End Using
  41.  
  42. End Sub
  43.  
  44. Private Shared Function GetText(ByRef lst As List(Of String)) As String
  45. Dim sb As New StringBuilder()
  46. For Each s As String In lst
  47. sb.AppendLine(s)
  48. Next
  49. Return sb.ToString()
  50. End Function
  51.  
  52. End Class
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Sorting in VB.Net
Next Thread in VB.NET Forum Timeline: Anyone with Sound Idea of Late Binding in VB.NET





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC