473,434 Members | 1,451 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,434 software developers and data experts.

Storing and retreiving rich text from MySQL in VB.net

Hi,

I have a question, i need to store the value of richtextbox to MySQL and retrive the value from MYSQL to richtextbox. can you give me a code in vb.net? and will the formating be affected like the font and alignment?

Can you please respond quicky?
Jul 15 '09 #1
6 7252
tlhintoq
3,525 Expert 2GB
Have you tried to do this on your own first?
Could you provide the code you've written thus far so the volunteers here can help you find why your code doesn't work?
Jul 15 '09 #2
@tlhintoq
Expand|Select|Wrap|Line Numbers
  1.     Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         conn = New MySqlConnection()
  3.         'connection 
  4.         myConnString = "conection to server"
  5.         conn.ConnectionString = myConnString
  6.         conn.Open()
  7.         If conn.State = ConnectionState.Closed Then conn.Open()
  8.         massDataTable.Clear()
  9.         massCommand = New MySqlCommand
  10.         massCommand = conn.CreateCommand
  11.         massCommand.CommandText = "SELECT * FROM `test` where `mark-1` = 1"
  12.         massAdapter.SelectCommand = massCommand
  13.         massAdapter.Fill(massDataTable)
  14.         With Me
  15.             .RichTextBox1.Text = (massDataTable.Rows(0)(1))
  16.         End With
  17.     End Sub
Jul 15 '09 #3
tlhintoq
3,525 Expert 2GB
It shouldn't be a game of 20 questions to try to help you. Common sense should tell you that the more information you provide the better someone can assist you.

There is no mention in your post of what/why your own code isn't working. Do you get an error? Do you get behavior different than you expected? Is your data going into the database but you are having trouble getting it back out, or can you retreive data that was already in the db but you can put your own in? Have you put breakpoints in your code and walked through it line-by-line? Is there a point where something is not as expected and you don't know why?
Jul 15 '09 #4
I have no problem on saving a text in mysql but yes i did, the error i have was when retriving it from Mysql, an error appears that the conversion from type 'Byte()' to type 'String' is not valid.
Jul 15 '09 #5
JamieHowarth0
533 Expert 512MB
evilson,

Does that error give a line number and an excerpt of code? This will help us isolate down the problem.
My suspicions are that you're trying to get the wrong column from your database into the richtextbox control - however, if you post the full error message up and stack trace then we'll be able to help you isolate the problem further.

codegecko
Jul 16 '09 #6
I think it's a runtime error. But dont worry, I do some research and i develope a code. I'll post the full code

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With Me
Try
Dim ms As MemoryStream = New MemoryStream
'initializing picture
.RichTextBox1.SaveFile(ms, RichTextBoxStreamType.RichText)
Dim bytBlobData(ms.Length - 1) As Byte
ms.Position = 0
ms.Read(bytBlobData, 0, ms.Length)

Dim DatabaseParameter As New MySql.Data.MySqlClient.MySqlParameter("@BlobData", MySql.Data.MySqlClient.MySqlDbType.Blob, bytBlobData.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, bytBlobData)
If conn.State = ConnectionState.Closed Then conn.Open()
massCommand = New MySqlCommand
massCommand = conn.CreateCommand
massCommand.CommandText = "insert into `test`" & _
"(`mark-2` ) " & _
"values(@BlobData)"
massCommand.Parameters.Add(DatabaseParameter)
massCommand.ExecuteNonQuery()
Catch ex As Exception
writelog("0001", userid, Now.Date.ToString("MM/dd/yyyy"), Microsoft.VisualBasic.Left(Now.TimeOfDay.ToString, 8), "TEST")
Exit Sub
End Try
End With
End Sub

Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conn = New MySqlConnection()
'connection
myConnString = "connection to server"
conn.ConnectionString = myConnString
conn.Open()
If conn.State = ConnectionState.Closed Then conn.Open()
massDataTable.Clear()
massCommand = New MySqlCommand
massCommand = conn.CreateCommand
massCommand.CommandText = "SELECT * FROM `test` where `mark-1` = 3"
massAdapter.SelectCommand = massCommand
massAdapter.Fill(massDataTable)
With Me
Dim rtfcontent As Byte() = DirectCast(massDataTable.Rows(0)(1), Byte())
If Not rtfcontent Is Nothing Then
Using stream As New IO.MemoryStream(rtfcontent)
.RichTextBox1.LoadFile(stream, RichTextBoxStreamType.RichText)
End Using
End If
End With
End Sub
Jul 16 '09 #7

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

Similar topics

3
by: Mark | last post by:
I have a website with an increasing amount of articles and news reports and so I am thinking of moving away from storing each article as a seperate page to having a single page and storing articles...
8
by: Steven | last post by:
Hi there, I am wanting to store price data as n.nn format, so if the user enters "1" the data that gets stored is "1.00" Is there a way to do this. Cheers Steven
8
by: Francesco Moi | last post by:
Hello. I'm parsing an XML file, and trying to store its contents into a MySQL database. But I've got problems. If I print the word before storing it, I get 'música' (OK). But if I store it...
1
by: Guy Erez | last post by:
Hi, I'm running queries with MySql 4.0.17 that return thousands of records. Because I need to present them in GUI, I returieve the results in chunks using LIMIT, for example - get first 100,...
0
by: Merek | last post by:
Hi all, We need to allow the user to store, view and edit blocks of rich text via an ASP.NET application. After adopting one of the many rich text editors out there that outputs HTML we are...
5
by: David Beck | last post by:
I have a need to store PDF, TIF and other files in TEXT fields on my SQL2000 Server and them retreive them and restore them to the disk (VB6). I created a table CIP_DOCUMENT_ID int no 4...
1
by: tomi.trescak | last post by:
Hi I have a problem with storing rich text in MySQL. I store rich text in MySQL (in column with type "text") which i get from Rich Textbox control. When i do reverse processing by trying to...
1
by: yucefrizk | last post by:
hello all, I'm trying to write a code to retreive data from a database to an excel file, I achieved my code and everything is going good by running it through unix, but when I create a webpage to...
4
by: pushpinderbagga | last post by:
hi I need help in storing and retreiving hindi text from myql... I have done the folowwing ... mysql_query("SET NAMES 'utf8'"); <META http-equiv=Content-Type content="text/html;...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.