Hi All,
I am working on a project for a refresher course I am doing in VB (It has been a long time since I touched it). The scope is VB.NET based employee information system using MySQL database.
I have managed to complete everything except for one step - File save (PDF) to the MySQL DB and ability to download the file. This I have never done before.
This is the MySQL DB Connect Method I Re-Use
Public Sub DBConnect()
Dim DatabaseName As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SYSTEM\db", "4", Nothing)
Dim server As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SYSTEM\db", "1", Nothing)
Dim userName As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SYSTEM\db", "2", Nothing)
Dim password As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SYSTEM\db", "3", Nothing)
If Not sConnection Is Nothing Then sConnection.Close()
sConnection.ConnectionString = String.Format("server={0}; user id={1}; password={2}; database={3}; pooling=false", server, userName, password, DatabaseName)
Try
sConnection.Open()
Catch ex As Exception
MsgBox(ex.Message)
MsgBox("ERROR 1001")
End Try
End Sub
Inserting a User Details into the DB
<pre>
Public Sub InsertUser()
DBConnect()
Dim sqlQuery As String = "INSERT INTO db_table (firstname, surname, age, dept) VALUES('" & fname_box.Text & "','" & sname_box.Text & "','" & age_box.Text & "','" & dept_box.Text & "')"
Dim sqlCommand As New MySqlCommand
With sqlCommand
.CommandText = sqlQuery
.Connection = sConnection
.ExecuteNonQuery()
End With
LoadUsers()
End Sub
My Question
I am looking for any ideas/suggestions you might have to upload a PDF document to the MySQL DB either as part of the above process (OR) as a separate process.
The Project has a requirement to attach a signed consent form for the user in PDF format, hence the requirement.
Essentially:
1. Browse for File
2. Select File
3. Upload or Save to MySQL LONGBLOB or VARBINARY
4. Ability to download PDF from button click.
What I have tried:
I have reviewed a few different solutions on youtube and other websites but each time I attempt one of them, I generally run into issues (mainly with the way in which I call the DB connection) which would take another hour to type and explain :) Essentially I am just looking for advice from someone who has achieved this previously.
Thank you in advance.