473,322 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Saving and Retrieving richtext to sql server

GridCode
Hi There

trying to save richtext to sql server. code below:


Expand|Select|Wrap|Line Numbers
  1.   SQLCat = "Catalog"
  2.         SQLDBTab = "RichTextData"
  3.         ConnStr = "Data Source=" & SQLDatSrc & ";Initial Catalog=" & SQLCat & ";User ID=" & SQLUser & ";Password=" & SQLUserPW & ";"
  4.  
  5.         QryStr = "INSERT INTO " & SQLDBTab & " (DataSheetID ,RichText) VALUES (1,@RichText)"
  6.         Dim cmd As SqlCommand = New SqlCommand(QryStr)
  7.         Dim params As SqlParameterCollection = cmd.Parameters
  8.         'params.Add("@RichText", System.Data.SqlDbType.Text)
  9.         params.Add("@RichText", SqlDbType.Text).Value = rtbDoc.Rtf.Normalize
  10.  
  11.         Dim conn As New SqlConnection(ConnStr)
  12.         cmd.CommandType = CommandType.Text
  13.         cmd.Connection = conn
  14.         Try
  15.             conn.Open()
  16.             cmd.ExecuteNonQuery()
  17.             MsgBox("RichText Saved to SQL")
  18.         Catch ex As Exception
  19.             Console.Write(ex.Message)
  20.         Finally
  21.             conn.Close()
  22.             conn.Dispose()
  23.         End Try
  24.     End Sub
Unable to get this back to richtext format.
data save into sql text field :{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttb l{\f0\fnil\fcharset0 Microsoft Sans . . .

Expand|Select|Wrap|Line Numbers
  1. when i try retrieve this with code beneath - not correct?
  2.  
  3.  Dim Dt As New DataTable
  4.         SQLCat = "Catalog"
  5.         SQLDBTab = "RichTextData"
  6.         ConnStr = "Data Source=" & SQLDatSrc & ";Initial Catalog=" & SQLCat & ";User ID=" & SQLUser & ";Password=" & SQLUserPW & ";"
  7.         QryStr = "SELECT RichText FROM " & SQLDBTab ' & " WHERE ImageID=" & 1
  8.  
  9.         Dim conn As New SqlConnection(ConnStr)
  10.         Dim Dap As New SqlClient.SqlDataAdapter(QryStr, conn)
  11.         Try
  12.             conn.Open()
  13.             Dap.Fill(Dt)
  14.         Catch ex As Exception
  15.             Console.Write(ex.Message)
  16.         Finally
  17.             conn.Close()
  18.             conn.Dispose()
  19.         End Try
  20.  
  21.         Dim Dr As DataRow
  22.         For Each Dr In Dt.Rows
  23.             rtbDoc.Rtf = (Dr.Item("RichText")) 'Does NOt Work? Format error?
  24.             rtbDoc.Text = (Dr.Item("RichText")) 'Just returns the native text, no settings, fonts applied ?
  25.         Next
Feb 15 '13 #1
0 1202

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Brian Wallis | last post by:
This may be a FAQ,but I cannot find it. I want to save user preferences, window sizes, recently opened file names, etc for a python application and I am looking for a package that does this in a...
7
by: Niyazi | last post by:
Hi, I developed an application and I am using SQL Server 2000 developer edition. I create my database and I have also created tbl_USER table. I have an ID, RealName, UserName, and UserPassword...
4
by: Val | last post by:
I have a DataSet with different types of data i.e. string, int , bool, etc. When i save it using the default WriteXml method, the data types are lost. When I use WriteXml(xmlWriter,...
4
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my...
6
by: Mark Denardo | last post by:
My question is similar to one someone posted a few months back, but I don't see any replies. Basically I want to be able to have users upload photos and save them in a database (as byte data)...
1
by: =?Utf-8?B?RkpZ?= | last post by:
ello, I have been using the DateTime.Now.ToUniversal() that works great until the recent daylight saving change. The server on which the application runs was patched to use the correct DST, but...
6
by: Mitesh | last post by:
How can I programattically retrieve MySQL server's port value through PHP?
7
by: Radu | last post by:
Hi. I have the following problem: The user needs to setup a request on a website, by deciding on a lot of questions. I want the website to dump an excel (CSV) file into a shared folder somewhere on...
0
by: giger | last post by:
if( MyFileLocal.PostedFile != null ) { HttpPostedFile myFile = MyFileLocal.PostedFile; int nDuzinaFajla = myFile.ContentLength; byte myData = new byte;...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.