Results 1 to 5 of 5

Thread: [RESOLVED] [2005] looping through files and importing

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Resolved [RESOLVED] [2005] looping through files and importing

    Ok I think I am close but am doing something wrong... Basically I have a directory of images that I am trying to import into a SQL table via Stored Proc... Getting the error:

    No mapping exists from object type System.IO.FileStream to a known managed provider native type.

    vb Code:
    1. Dim stFileDir As String = "U:\styleimages"
    2.         Dim cmd As New SqlCommand
    3.  
    4.         conn.Open()
    5.         With cmd
    6.             .Connection = conn
    7.             .CommandType = CommandType.StoredProcedure
    8.             .CommandText = "InsertStyleImage"
    9.             For Each FileName As String In Directory.GetFiles(stFileDir)
    10.                 Dim MyFileInfo As New FileInfo(FileName)
    11.                 .Parameters.Clear()
    12.                 .Parameters.AddWithValue("@ImageName", MyFileInfo.Name)
    13.                 .Parameters.AddWithValue("@ImageData", MyFileInfo.OpenRead)
    14.                 .Parameters.AddWithValue("@ImageSize", MyFileInfo.Length)
    15.                 .Parameters.AddWithValue("@ImageType", MyFileInfo.GetType)
    16.                 .Parameters.AddWithValue("@StyleNo", " ")
    17.                 .ExecuteNonQuery()
    18.             Next
    19.             MsgBox("Done!")
    20.         End With
    21.         conn.Close()
    22.  
    23.     End Sub

    I am guessing it is in MyFileInfo.OpenRead but not sure what I should use.

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2005] looping through files and importing

    Take a look at JMC's code on saving an image into a database field:

    http://www.vbforums.com/showthread.p...ighlight=image

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: [2005] looping through files and importing

    thanks.... but I would think I could stick to this format and treat it as any type of file... What it if it wasn't a image?

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [RESOLVED] [2005] looping through files and importing

    As long as you get it into a memory stream, JMC's method will work for any file type, just when you extract it out, you have to know what it is.

  5. #5
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: [RESOLVED] [2005] looping through files and importing

    wondering if this will do

    Code:
    .Parameters.AddWithValue("@ImageData", New IO.BinaryReader(MyFileInfo.OpenRead).ReadBytes(MyFileInfo.OpenRead.Length))
    __________________
    Rate the posts that helped you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width