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?
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