我希望使用带有Windows格式的Windows窗体存储在SQL Server数据库中的图像检索rtf文本,格式和图像格式正确。
这是以Windows格式存储的代码:
Dim cmd As New SqlCommand("UPDATE questions SET ques_rich = @ques_rich WHERE quest_no = 1 ", con)
con.Open()
cmd.Parameters.AddWithValue("@ques_rich", RichTextBox1.Rtf)
cmd.ExecuteNonQuery()
con.Close()
这是用于在asp.net中检索的代码:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim con As New SqlConnection("Data Source=AHMEDHASHEM\SQLEXPRESS;Initial Catalog=test;Integrated Security=True")
Dim cmd1 As New SqlClient.SqlCommand
Dim tbl As New DataTable
Dim reader As SqlClient.SqlDataReader
Dim sql As String
sql = "select * from questions where quest_no = 1"
cmd1 = New SqlClient.SqlCommand(sql, con)
Dim ds1 As New DataSet()
Dim Adpt1 As New SqlDataAdapter(sql, con)
Adpt1.Fill(ds1, "questions")
'rc = ds1.Tables(0).Rows.Count
con.Open()
tbxTinymce.Text = ds1.Tables("questions").Rows(0)("ques_rich")
con.Close()
End Sub
注意:我使用tinymce和freetextbox控件
同时使用带有此代码的Word文档:
Dim wordApp As New Microsoft.Office.Interop.Word.ApplicationClass()
Dim nullobj As Object = System.Reflection.Missing.Value
Dim doc As Word.Document = wordApp.Documents.Open("c:\goinstall.doc")
Dim doc1 As Word.Document = wordApp.ActiveDocument
Dim m_Content As String = doc1.Content.Text
FreeTextBox1.Text = m_Content
doc.Close(nullobj, nullobj, nullobj)
该代码仅检索没有图像和格式的文本
答案 0 :(得分:0)
以下代码接受来自文件上载流的图像,将其转换为字节数组并将其存储在会话对象中,以便以后检索并存储到Oracle数据库中的blob中。
' Easy enough to load a file from a stream, here I get a image from a file upload
Dim TheStream As Stream = file1.PostedFile.InputStream
' Need a variable to store the image in
Dim origimage As System.Drawing.Image
' Same the uploaded image to the variable
origimage = System.Drawing.Image.FromStream(TheStream)
' Now we need to convert it to a bye array
Dim ms2 As New System.IO.MemoryStream
' First I scale it, I don't need a huge image, you won't need to do this
origimage = ScaleImage(origimage, 320, 200) ' new scaling method
' I save it to the memory stream in preparation to converting to a byte array
origimage.Save(ms2, Imaging.ImageFormat.Jpeg)
' Here I convert the file
Dim MyPhoto() As Byte = ms2.GetBuffer ' The scaled image is now stored in memory as a byte array
Session("ThePhoto") = MyPhoto ' put it into the session to retreive later
' Release the memory
ms2.Dispose()
origimage.Dispose()
显然,其中一些与您的问题无关。您需要使用某种文件流加载RTF文件,然后将文件转换为字节数组。希望这有助于指出你正确的方向。