Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
VB
Dim fd As New OpenFileDialog
       Dim fullFileName() As String = fd.FileName.Split("\")
       Dim fname As String = fullFileName.Last.ToString
       Dim fileContent() As Byte

       Dim fstream As New FileStream(fd.FileName, FileMode.Open)
       Dim Breader As New BinaryReader(fstream)
       fileContent = Breader.ReadBytes(fstream.Length)
       fstream.Close()
       Breader.Close()
       Dim cmd As New SqlCommand
       With cmd
           .Connection = conn
           .Parameters.Clear()
           .CommandText = "insert into TbPdf (fileName,fileData) values (@fileName, @fileData)"
           .CommandType = CommandType.Text
           .Parameters.AddWithValue("@fileName", fname)
           .Parameters.AddWithValue("@fileID", fileContent)
           conn.Open()
           .ExecuteNonQuery()
       End With
       MsgBox("تم  الحفظ")


What I have tried:

what is wrong in my code
i want save file in database sql server and restore it
Posted
Updated 20-Jan-18 20:13pm
v2
Comments
PIEBALDconsult 21-Jan-18 2:08am    
Not sure about anything else, but your SQL parameter names don't match.

1 solution

Um.
Look at your code:
C#
Dim fd As New OpenFileDialog
Dim fullFileName() As String = fd.FileName.Split("\")
fd is a new OpenFileDialog - so it's never been presented to the user, it's never had a file selected, so it doesn't have a file name. Did you mean to call fd.ShowDialog at some point?
 
Share this answer
 
Comments
Member 13573482 21-Jan-18 2:39am    
i didn't get you
you mean this is mistake here
Dim fd As New OpenFileDialog
Dim fullFileName() As String = fd.FileName.Split("\")
Member 13573482 21-Jan-18 2:41am    
Dim fd As New OpenFileDialog
'fd.Filter() = "|*.pdf"
If fd.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox10.Text = fd.FileName

End If
that is my code in button browse
an0ther1 21-Jan-18 19:23pm    
Then your code should get the value from TextBox10.Text. Your code in your question at the top creates another OpenFileDialog.

Kind Regards

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