VB.net将.msg文件插入到访问数据库中

时间:2016-02-23 15:52:59

标签: vb.net ms-access

我只是尝试使用以下代码将.msg(outlook email)插入访问数据库字段(Data type = Attachment)。

    Dim filePath As String = RemoveStuff(frmMain.tbAppEmail.Text)
    Dim filename As String = Path.GetFileName(filePath)
    Dim ext As String = Path.GetExtension(filename)
    Dim contenttype As String = String.Empty


    Select Case ext
        Case ".msg"
            contenttype = "application/vnd.ms-outlook"
            Exit Select

    End Select

    Try
        Dim dbProvider As String
        Dim dbSource As String
        Dim Query As String

        If contenttype <> String.Empty Then
            Dim fs As Stream = New FileStream(filePath, FileMode.Open, FileAccess.Read)
            Dim br As New BinaryReader(fs)
            Dim bytes As Byte() = br.ReadBytes(fs.Length)

            dbProvider = "PROVIDER=Microsoft.ACE.OLEDB.12.0;"

            Query = "INSERT INTO tblAppointments (AppEmail) VALUES (?)"

            dbSource = "Data Source = " & DatabaseLoc & "; Persist Security Info=False;"

            Using con = New OleDb.OleDbConnection(dbProvider & dbSource)
                Using cmd As New OleDb.OleDbCommand(Query, con)
                    con.Open()

                    cmd.Parameters.AddWithValue("@p1", bytes)   'AppDate

                    cmd.ExecuteNonQuery()

                End Using
            End Using
        End If
    Catch ex As Exception
        MsgBox("An Error Has Occoured: " & ex.Message, MsgBoxStyle.Exclamation, "ERROR")
        frmMain.Cursor = Cursors.Default
        Exit Sub
    End Try

我得到的错误信息是 - “INSERT INTO查询不能包含多值字段。”

0 个答案:

没有答案