如何在SQL中使用富文本框保存图像和格式化文本,并在水晶报表VB.NET上显示
我尝试下面的代码在富文本框中插入图像 .
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
Dim ff As New OpenFileDialog
ff.Filter = "Image Files|*.gif;*.jpg;*.png;*.bmp"
ff.ShowDialog()
Dim img As System.Drawing.Image = System.Drawing.Image.FromFile(ff.FileName)
Dim orgData = Clipboard.GetDataObject
Clipboard.SetImage(img)
Me.rtb.Paste()
Clipboard.SetDataObject(orgData)
End Sub
在这里我将它插入到SQL中
Dim sname As Integer = Integer.Parse(txt1.Text)
Dim sfname As Integer = 2
Dim scnic As String = rtb.rtf
query &= "INSERT INTO tencmpC1 (qnumber,topic,Umcq)"
query &= "VALUES (@qnumber, @topic,@Umcq )"
Using conn As New SqlConnection(strConn)
Using comm As New SqlCommand()
With comm
.Connection = conn
.CommandType = CommandType.Text
.CommandText = query
.Parameters.AddWithValue("@qnumber", sname)
.Parameters.AddWithValue("@topic", sfname)
.Parameters.AddWithValue("@Umcq", scnic)
conn.Open()
comm.ExecuteNonQuery()
txt10.Text = "question saved "
End With
End Using
我使用nvarchar(max)作为"datatype to SQL field"用于RTB文本 . 我正在使用textformate进行水晶报告"crRTFText" . 请指导我必须做哪些改变? Thanks in advance
1 回答
您不能在字符字段中存储二进制数据(在本例中是您要插入RTB的图片) . 根据您正在使用的SQL后端,您需要将数据存储在BLOB / CLOB列中 .
有关示例,请参见here .