Hi,
I'm trying to upload a PDF and store it in a database. At the moment we're using mySql but we have plans to change to SQL in the future.
I've currently got a function that takes the Binary data as a Byte array, but at the moment when it inserts it it inserts the string "System.Byte[]" in binary format!
What do I do with the byte array to correctly save the PDF data?
This is my function, it's simple enough:
1 Public Function File_Upload(ByVal DocumentID As Integer, ByVal Data As String, ByVal LiveFrom As DateTime) As Boolean
2
3 Dim myConnection As MySqlConnection
4 Dim myCommand As MySqlCommand
5
6 myConnection = New MySqlConnection(ConfigurationManager.ConnectionStrings.Item("MySql").ConnectionString)
7
8 Dim strSQL As New System.Text.StringBuilder
9 strSQL.Append("INSERT INTO files (Document_ID, pdf_data, version, live_from) VALUES (")
10 strSQL.Append(DocumentID)
11 strSQL.Append(",'")
12 strSQL.Append(Data)
13 strSQL.Append("', ")
14 strSQL.Append(GetVersionNumber(DocumentID))
15 strSQL.Append(", '")
16 strSQL.Append(LiveFrom.Year & "-" & LiveFrom.Month & "-" & LiveFrom.Day & " 00:00:00")
17 strSQL.Append("')")
18
19 myConnection.Open()
20 myCommand = New MySqlCommand(strSQL.ToString, myConnection)
21
22 Return myCommand.ExecuteNonQuery > 0
23
24 End Function
I call it like...
wsDocument.File_Upload(Request.QueryString("DocumentID"), fuFile.FileBytes, GetLiveFrom())
"fuFile" is the built in .NET 2 file upload control.
I'm trying to upload a PDF and store it in a database. At the moment we're using mySql but we have plans to change to SQL in the future.
I've currently got a function that takes the Binary data as a Byte array, but at the moment when it inserts it it inserts the string "System.Byte[]" in binary format!
What do I do with the byte array to correctly save the PDF data?
This is my function, it's simple enough:
1 Public Function File_Upload(ByVal DocumentID As Integer, ByVal Data As String, ByVal LiveFrom As DateTime) As Boolean
2
3 Dim myConnection As MySqlConnection
4 Dim myCommand As MySqlCommand
5
6 myConnection = New MySqlConnection(ConfigurationManager.ConnectionStrings.Item("MySql").ConnectionString)
7
8 Dim strSQL As New System.Text.StringBuilder
9 strSQL.Append("INSERT INTO files (Document_ID, pdf_data, version, live_from) VALUES (")
10 strSQL.Append(DocumentID)
11 strSQL.Append(",'")
12 strSQL.Append(Data)
13 strSQL.Append("', ")
14 strSQL.Append(GetVersionNumber(DocumentID))
15 strSQL.Append(", '")
16 strSQL.Append(LiveFrom.Year & "-" & LiveFrom.Month & "-" & LiveFrom.Day & " 00:00:00")
17 strSQL.Append("')")
18
19 myConnection.Open()
20 myCommand = New MySqlCommand(strSQL.ToString, myConnection)
21
22 Return myCommand.ExecuteNonQuery > 0
23
24 End Function
I call it like...
wsDocument.File_Upload(Request.QueryString("DocumentID"), fuFile.FileBytes, GetLiveFrom())
"fuFile" is the built in .NET 2 file upload control.