从Access文件保存并读取RichText,Image为SLOW

时间:2017-02-13 21:23:53

标签: vb.net

如果我使用以下代码将rtf数据写入和读取访问.mdf文件,则快速保存数据但读取速度很慢。

我测试的rtf文件大小为1毫克,包含大约10行粗体和4张小图像。

无论如何都要更快地阅读它,

请注意,如果从文件中加载rtf大约需要1秒,

保存数据

Dim constring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\paul\Documents\Code.mdb"

Using myconnection As New OleDbConnection(constring)
    myconnection.Open()
    Dim sqlQry As String = "INSERT INTO [table1] ([Code]) VALUES (@Code)"
    Using cmd As New OleDbCommand(sqlQry, myconnection)
        cmd.Parameters.AddWithValue("@code", RTB1.Rtf)
        cmd.ExecuteNonQuery()
    End Using
    myconnection.Close()
End Using

阅读数据

Dim constring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\paul\Documents\Code.mdb"

Dim ds As New DataSet
Using myconnection As New OleDbConnection(constring)
    myconnection.Open()
    Dim strSql As String = "SELECT * FROM table1"
    Using cmd As New OleDbCommand(strSql, myconnection)
        Dim da As New OleDbDataAdapter(cmd)
        da.Fill(ds, "Table")
    End Using
    myconnection.Close()
End Using

Me.RTB1.rtf = ds.Tables(0).Rows(0).Item(1)

0 个答案:

没有答案