locked
how to insert image RRS feed

  • Question

  • User-432912715 posted

    I want to insert image into ms access using vb.net, what is the command string for inserting "Radiobutton.image".

    plz help me

    Thursday, May 29, 2008 1:32 AM

Answers

  • User-691438185 posted

    pavanikatari,

    The question is quite common and too general to provide the exact answer. As far as I've knwon, there is code snippet by ahmedilyas in this thread is the best solution for this kind of problems:

            Dim theFS As New FileStream(Application.StartupPath & "\testImage.JPG", FileMode.Open)
            Dim theBytes(theFS.Length) As Byte
    
            theFS.Read(theBytes, 0, theBytes.Length)
            theFS.Close()
    
            Dim theQuery As New OleDbCommand("INSERT INTO Table1([image]) VALUES(?)", New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\db1.mdb;User Id=admin;Password=;"))
            Dim p1 As New OleDbParameter("@p1", OleDbType.Binary)
            p1.Value = theBytes
            theQuery.Parameters.Add(p1)
            theQuery.Connection.Open()
            theQuery.ExecuteNonQuery()
            theQuery.Connection.Close()
    

    In addition, you can read the article Storing Binary Files Directly in the Database Using ASP.NET 2.0

    Hope that helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 4, 2008 2:06 AM