'将RichTextBox的内容直接写入数据库:
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim mstream As System.IO.MemoryStream = New System.IO.MemoryStream()
Me.richTextBox1.SaveFile(mstream, RichTextBoxStreamType.RichText)
'将流转换成数组
Dim bWrite() As Byte = mstream.ToArray()
'将数组写入数据库
Dim pram() As System.Data.SqlClient.SqlParameter = {sqlHelper.MakeInParam("@XX", System.Data.SqlDbType.Image)}
pram(0).Value = bWrite
sqlHelper.RunSql("insert into XXX (XX) values (@XX)", pram)
End Sub
'将数据库中的RTF读出并填充到RichTextBox
Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs)
'从数据库中读出数据
Dim dt As DataTable = sqlHelper.GetDataTable("select XX from XXX where .....")
Dim bWrite() As Byte = CType(dt.Rows(0)(0), Byte())
'将数组转换成stream
Dim mstream As System.IO.MemoryStream = New System.IO.MemoryStream(bWrite, False)
'将stream填充到RichTextBox
Me.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText)
End Sub
RichTextBox与二进制Word
最新推荐文章于 2021-07-09 12:13:18 发布