The following code performs an insert of an MP4 file into a database table. I also have code that streams the binary file from SQL server into a media player. Works flawlessly. My issue is I have additional fields that I want to insert into the database table in addition to Name, ContentType and Data. My problem is I do not know how to write the code to make the additional fields part of the below insert statement. I tried to write some code but my additional code caused two records to be created. One record was created with my new fields and the other with the Name, ContentType and Data (mp4 binary file) fields. I would absolutely need the information in the same row of data.
The fields I want to add are username or userid of logged in user(I know this one may be more complicated,
savedfor varchar (150)
bioname varchar (150)
sharewith varchar (150)
description varchar (500)
Here is my current code:
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs)
' Read the file and convert it to Byte Array
Dim filePath As String = FileUpload1.PostedFile.FileName
Dim filename As String = Path.GetFileName(filePath)
Dim ext As String = Path.GetExtension(filename)
Dim contenttype As String = String.Empty
'Set the contenttype based on File Extension
Select Case ext
contenttype = "video/mp4"
If contenttype <> String.Empty Then
Dim fs As Stream = FileUpload1.PostedFile.InputStream
Dim br As New BinaryReader(fs)
Dim bytes As Byte() = br.ReadBytes(fs.Length)
'insert the file into database
Dim strQuery As String = "insert into tblFiles" _
& "(Name, ContentType, Data)" _
& " values (@Name, @ContentType, @Data)"
Dim cmd As New SqlCommand(strQuery)
cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = filename
cmd.Parameters.Add("@ContentType", SqlDbType.VarChar).Value _
cmd.Parameters.Add("@Data", SqlDbType.Binary).Value = bytes
lblMessage.ForeColor = System.Drawing.Color.Green
lblMessage.Text = "File Uploaded Successfully"
lblMessage.ForeColor = System.Drawing.Color.Red
lblMessage.Text = "" _
& " Upload MP4 format files only"
Here is the Connection:
Public Function InsertUpdateData(ByVal cmd As SqlCommand) As Boolean
Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings("SQL2008R2_504887_golivefitnesConnectionString").ConnectionString
Dim con As New SqlConnection(strConnString)
cmd.CommandType = CommandType.Text
cmd.Connection = con
Catch ex As Exception