0

I am simply trying to insert a .msg (outlook email) into an access database field (Data type = Attachment) using the following code.

    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

the error message i am getting is - "An INSERT INTO query cannot contain a multi-valued field."

Lickrob
  • 61
  • 2
  • 11

0 Answers0