Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
this is my coding but its not opening the file. please help me
C#
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ATECH1\Documents\pdf.accdb")
        Dim DestFilePath As String = "‪C:\Documents\pdf.accdb "
        Dim RetVal As Long
        Dim FieldLen As String

        con.Open()
        Dim cmd As New OleDbCommand("select filename from files where filename= '" & TextBox1.Text & "' ", con)
        ' With cmd.Parameters
        '.AddWithValue("@filename", TextBox1.Text)

        Try

            Dim AccessDataReader As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
            AccessDataReader.Read()
            FieldLen = AccessDataReader.Item("filename").ToString
            Dim BlobByteArray(FieldLen - 0) As Byte
            Dim startIndex As Integer = 0
            RetVal = AccessDataReader.GetBytes(0, startIndex, BlobByteArray, 0, BlobByteArray.Length)

            Dim FileStreamObject As New System.IO.FileStream(DestFilePath, IO.FileMode.Open, IO.FileAccess.Write)
            FileStreamObject.Write(BlobByteArray, 0, BlobByteArray.Length)
            FileStreamObject.Close()
            AccessDataReader.Close()
            con.Close()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
Posted
Updated 5-Nov-14 23:23pm
v2

1 solution

Whats the error/exception and where it is ?
 
Share this answer
 
Comments
Member 11211432 6-Nov-14 6:50am    
System.InvalidOperationException: No data exists for row/column
_Vitor Garcia_ 6-Nov-14 7:03am    
And in which line is it thrown ?
Member 11211432 6-Nov-14 7:18am    
line 149
however I have now changed the coding here is the coding
Dim sFilePath As String
Dim buffer As Byte()
Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ATECH1\Documents\pdf.accdb")
conn.Open()
Dim cmd As New OleDbCommand("Select filename from files WHERE filename = '" & TextBox1.Text & "'", conn)
' buffer = cmd.ExecuteScalar()
sFilePath = cmd.ExecuteScalar()
conn.Close()

sFilePath = System.IO.Path.GetTempFileName()
System.IO.File.Move(sFilePath, System.IO.Path.ChangeExtension(sFilePath, ".pdf"))
sFilePath = System.IO.Path.ChangeExtension(sFilePath, ".pdf")
Dim fileStreamObject As New System.IO.FileStream(sFilePath, IO.FileMode.Open, IO.FileAccess.Write)
Dim act As Action(Of String) = New Action(Of String)(AddressOf OpenPDFFile)
act.BeginInvoke(sFilePath, Nothing, Nothing)
fileStreamObject.Close()
End Sub
but i get the error Adobe reader could not open TED66.pdf because the file it is either not supportted or the file has been damaged
_Vitor Garcia_ 6-Nov-14 7:31am    
Sorry. I can't help you if you don't want to.

When you write
line 149
however I have now changed the coding here is the coding

without even pointing changes what do you expect from me ? To figure it out? Im sorry, but i can't.
Member 11211432 6-Nov-14 7:35am    
The one I have just Submitted its a new one, because the old one even myself its was getting to difficult to understand the error. so started to do new coding which is different. thanks alot. im sorry for that

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900