AllExperts > Experts 
Search      

VB.NET

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More VB.NET Answers
Question Library

Ask a question about VB.NET
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Chris
Expertise
I can answer pretty much any question relating to VB.NET and its use in a Windows environment. I specialize in ASP.NET web development and MSSQL database access.

Experience
I have over 5 years of industry experience using VB.NET and other .NET technologies for web and database development.

Education/Credentials
I have some college education, but does it really matter in this field of work?

 
   

You are here:  Experts > Computing/Technology > Basic > VB.NET > Get error invalid parameter loading images from SQL server !!

Topic: VB.NET



Expert: Chris
Date: 9/28/2007
Subject: Get error invalid parameter loading images from SQL server !!

Question
Dear Chris,
I'm new in VB.NET and trying to load image from SQL server using Picturebox control but it was showing errors invalid parameter. I have debugged this and see below hightligh error.  

So Could you mind to have a look following my project and show me how to fix it.

.Using objdata As New clsmaindb
           With objdata
               Try
                   .SQL = "Select * from tbl_Pictures" & _
                       " Where PixID=@pixID"
                   .InitializeCommand()
                   .AddParameter("@pixID", SqlDbType.Int, 12, CInt(txtimgid1.Text))
                   .OpenConnection()
                   .InitializeDataAdapter()
                   Dim ds As New DataSet
                   .FillDataSet(ds, "Image")

                   If ds.Tables(0).Rows.Count > 0 Then
                       lblPixName.Text = ds.Tables(0).Rows(0).Item("PixName").ToString
                       Dim mybyte() As Byte = ds.Tables(0).Rows(0).Item("Pix")
                       If mybyte.Length > 0 Then
                           Dim myStream As New MemoryStream(mybyte, True)
                           
                           PE.Image = Image.FromStream(myStream)//get error here..
                           myStream.Close()
                       End If

Answer
You should be able to do this, I think it's just not happy because you're using Image.FromStream, I use this same system of storing image data in SQL Server and loading it into a Bitmap object.  On the line throwing the error, try this instead:

Dim mybyte() As Byte = ds.Tables(0).Rows(0).Item("Pix")
If mybyte.Length > 0 Then
 PE.Image = New System.Drawing.Bitmap(New System.IO.MemoryStream(mbyte))
End If

Hope this helps!

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.