?
Solved

Save MP3 Files In Database

Posted on 2006-03-29
11
Medium Priority
?
279 Views
Last Modified: 2006-11-18
Hi

I am working on a little program which should "hopefully" let the user upload an mp3 file from their harddrive to a database for storage.

Anyone know how to do this?

Thanks
0
Comment
Question by:narmi2
11 Comments
 
LVL 11

Expert Comment

by:Ramesh Srinivas
ID: 16319658
Hi,

You would do this in the same way as images - i.e convert the files data into binary.

You would then store it in the database.

Examples of how to achieve this:

http://www.stardeveloper.com/articles/display.html?article=2003031201&page=1
http://www.eggheadcafe.com/articles/20041022.asp


regards,

KS
0
 
LVL 9

Accepted Solution

by:
Naveen Swamy earned 1600 total points
ID: 16319959
0
 
LVL 21

Expert Comment

by:oleggold
ID: 16320687
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 21

Expert Comment

by:oleggold
ID: 16320707
This seems exactly what You need:
http://www.freevbcode.com/ShowCode.asp?ID=1127
0
 
LVL 1

Author Comment

by:narmi2
ID: 16321705
Thanks for the replies.

In the database, what datatype do I set the column as?  image or binary?  I'm thinking binary!?
0
 
LVL 7

Assisted Solution

by:SweetsGreen
SweetsGreen earned 400 total points
ID: 16322142
image
0
 
LVL 1

Author Comment

by:narmi2
ID: 16322908
Thanks!

Ok I now have the following code which does NOT work properly.  I upload a 23k file and it returns a 1k file ???

THE CODE -----------------


    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        WriteDocumentToDB2("c:\test.doc")
    End Sub

    Private Sub WriteDocumentToDB2(ByVal sInDoc As String)
        Dim objDataSet As DataSet
        Dim objSQLCommand As SqlCommand
        Dim objSQLConnection As New SqlConnection("connection string")
        Dim strInsertCommand As String = "insert into table (name, phone, docs) values (@name, @phone, @docs)"

        Dim objFileStream As New FileStream(sInDoc, FileMode.OpenOrCreate, FileAccess.Read)
        Dim objDocBytes(objFileStream.Length) As Byte

        objFileStream.Read(objDocBytes, 0, objFileStream.Length)
        objFileStream.Close()

        objSQLCommand = New SqlCommand(strInsertCommand, objSQLConnection)

        objSQLCommand.Parameters.Add(New SqlParameter("@name", SqlDbType.NVarChar, 50))
        objSQLCommand.Parameters("@name").Value = "Some Value Here"

        objSQLCommand.Parameters.Add(New SqlParameter("@phone", SqlDbType.NVarChar, 50))
        objSQLCommand.Parameters("@phone").Value = "Some Value Here"

        objSQLCommand.Parameters.Add(New SqlParameter("@docs", SqlDbType.Image, 16))
        objSQLCommand.Parameters("@docs").Value = objDocBytes

        objSQLCommand.Connection.Open()
        objSQLCommand.ExecuteNonQuery()
        objSQLCommand.Connection.Close()
    End Sub

    Private Sub btnRestore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRestore.Click
        ReadDocumentFromDB2("c:\a\test.doc")
    End Sub


    Public Sub ReadDocumentFromDB2(ByVal sOutDoc As String)
        Dim objDataSet As DataSet
        Dim objSQLConnection As New SqlConnection("connection string")
        Dim objSQLDataAdapter As SqlDataAdapter

        Dim objSelectCommand As String = "select docs from table1 where id = @id"

        objSQLDataAdapter = New SqlDataAdapter(objSelectCommand, objSQLConnection)

        objSQLDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@id", SqlDbType.Int, 4))
        objSQLDataAdapter.SelectCommand.Parameters("@id").Value = "0"

        objDataSet = New DataSet
        objSQLDataAdapter.Fill(objDataSet)

        Dim objDataRow As DataRow
        objDataRow = objDataSet.Tables(0).Rows(0)

        Dim objDocBytes() As Byte
        objDocBytes = objDataRow("docs")

        Dim K As Long
        K = UBound(objDocBytes)

        Dim objFileStream As New FileStream(sOutDoc, FileMode.OpenOrCreate, FileAccess.Write)
        objFileStream.Write(objDocBytes, 0, K)
        objFileStream.Close()
        objFileStream = Nothing
    End Sub
0
 
LVL 1

Author Comment

by:narmi2
ID: 16323099
To be more precise it uploads 23.040 bytes and returns 15 bytes!  That 15 bytes is very close to the 16 byte image datatype: i.e. objSQLCommand.Parameters.Add(New SqlParameter("@docs", SqlDbType.Image, 16))

Any ideas?
0
 
LVL 1

Author Comment

by:narmi2
ID: 16323105
sorry i mean 23,040 bytes and 15 bytes
0
 
LVL 1

Author Comment

by:narmi2
ID: 16340591
If I could offer more points I would, as this is very urgent.  anyone know from the code posted above, why I only get a 15 byte file when i upload a 23,050 byte file ???

Please help.
0
 
LVL 1

Author Comment

by:narmi2
ID: 16342601
IT'S ALIVE !!!

THANKS :D
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question