Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7051439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:15:49+00:00 2026-05-28T03:15:49+00:00

I have a desktop application using vb.net, to process some excel files, those files

  • 0

I have a desktop application using vb.net, to process some excel files, those files are stored in a sql server database.
Here is the code I have:

Try
        conDCS.Open()
        comDCS.Connection = conDCS
        comDCS.CommandType = CommandType.Text
        comDCS.CommandText = "select top 2 [Filename], [File] " & _
                            "from tblFiles (nolock) " & _
                            "where ([Filename] like 'DIG%' or [Filename] like 'FAC%') and " & _
                            "(UploadDate>='" & FromDate & "' and UploadDate<'" & ToDate & "')"
        comDCS.ExecuteNonQuery()
        rdrDCS = comDCS.ExecuteReader
        If rdrDCS.HasRows Then
            While rdrDCS.Read
                Dim imageInBytes As Byte() = rdrDCS(1)
                Dim memoryStream As System.IO.MemoryStream = New System.IO.MemoryStream(imageInBytes, False)
                Dim image As System.Drawing.Image = System.Drawing.Image.FromStream(memoryStream)
                image.Save(TempPath & rdrDCS(0))
            End While
            ToProcess = True
        End If
        rdrDCS.Close()
    Catch ex As Exception
        ToProcess = False
        MessageBox.Show("Error accessing to the files: " & ex.Message)
    Finally
        conDCS.Close()
    End Try

I’m getting: “Parameter is not valid” in this line:

Dim image As System.Drawing.Image = System.Drawing.Image.FromStream(memoryStream)

I have understood that this error is related to an invalid image data, but I can’t figure it out what could be the problem.

imageInBytes has a length of 41473. And some items of the array have zero as value.

What could be wrong here, or perhaps, can anyone supply a working code to achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:15:50+00:00Added an answer on May 28, 2026 at 3:15 am

    We use a common method to save a file from a database field to a file:

    Public Function FieldToFile(ByVal sFileName As String, ByVal theField As Object) As Boolean
        ' Exceptions are handled by the caller
    
        If theField IsNot DBNull.Value Then
            Using oStream As New System.IO.FileStream(sFileName, IO.FileMode.Create, IO.FileAccess.Write)
                If oStream IsNot Nothing Then
                    Dim aBytes As Byte()
    
                    aBytes = DirectCast(theField, Byte())
    
                    oStream.Write(aBytes, 0, aBytes.Length)
                    oStream.Close()
                End If
            End Using
        End If
    
        Return True
    End Function
    

    This can be called as follows:

    Call FieldToFile(someFileName, rdrDCS(1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C#.NET desktop application using SQL Compact edition as data store. The
I have a desktop application (C# .NET 3.5) that uses a SQL server for
I am analyzing some .net desktop application. I have found that code: if (System.Environment.ProcessorCount
I am developing desktop application using vb.net and vs2008. I have a DropDownList that
I have developed a desktop application (.NET 2.0) and it needs to get some
Hey I am developing an desktop application using Spring and Hibernate, and I have
We have a dilemma; developing desktop application using Matisse or Jigloo.. Matisse has this
In our desktop application, we have implemented a simple search engine using an inverted
We have a desktop application that has been using MapPoint for displaying data on
Environment: Visual Studio Ultimate 2010 Windows XP WPF Desktop Application using .NET 4.0 We

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.