Error in loading images from database "Invalid Parameter Used"

G

Guest

I am having problem loading the image from the database. It gives this error:
"Invalid parameter used."
This is my source code:
Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog
Dim strCn As String = "Data Source=DATABASE\BARCA;" & _
"Initial Catalog=MIS;Integrated Security=SSPI"
Dim cn As SqlConnection = New SqlConnection(strCn)
Dim fs As IO.FileStream
Dim br As IO.BinaryReader
Dim ms As IO.MemoryStream
Public Shared connectionString As String =
ConfigurationSettings.AppSettings("connectionString")
Public Shared sqlConnection As SqlConnection = Nothing

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
Try
sqlConnection = New SqlConnection(connectionString)
sqlConnection.Open()
Dim cmd As SqlCommand
cmd = New SqlCommand("spQueryItems", sqlConnection)
cmd.CommandType = CommandType.StoredProcedure
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(dt)
Dim c As Integer = dt.Rows.Count
If c > 0 Then
Dim bytBLOBData() As Byte = _
dt.Rows(c - 1).Item(17)
Dim stmBLOBData As New MemoryStream(bytBLOBData)
picBLOB.Image = Image.FromStream(stmBLOBData)
End If
txtDesc.Text = dt.Rows(0).Item(1)
Catch ex As Exception

End Try
End Sub

I put the connectionstring in app.config as testing
but I used web services to connect to the database in the real project.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="ConnectionString" value="Data
Source=DATABASE\BARCA;Trusted_Connection=true;user id=Admin;password=;initial
Catalog=MIS"/>
<!--<add key="MIS.MISWeb.Service1"
value="http://localhost/DistributedMIS/MISServ.asmx"/><add
key="MIS.MISWebServ.Service1"
value="http://localhost/DistributedMIS/Service1.asmx"/>-->
</appSettings>

</configuration>

I get the "invalid parameter used" error when running on VB.NET not on SQL
Server. this part when executed returns that error:
picBLOB.Image = Image.FromStream(stmBLOBData)
It always get the last record. I want to get the other records from the
database?
The SQL query is a stored procedure that gets all records from a view or
table name "vwItems" and "Items" respectively. This the content of the
"spQueryItems":
CREATE procedure spQueryItems
as
Select ItemID, ItemDesc, UnitID, ColorID, SizeID, Length, Width, Height,
Diameter, Package, InnerLength, InnerWidth, InnerHeight, OuterQty,
OuterLength, OuterWidth, OuterHeight, Photo, UnitPrice, CurID, TypeID,
DateEntered, OtherSpec, UnitDesc, UnitAbrv, ColorDesc, SizeAbrev, SizeDesc,
CurDesc, TypeDesc from vwItems order by ItemID
GO

How can I get all records to display one by one or querying the specific row
from the database?

Can you help me? Thanks for replying!
Arnold
 
C

Cor Ligthert

Arnold,

I take the errors one by one as I see them. Please reply if it fits or not.

This one
Dim bytBLOBData() As Byte = _
dt.Rows(c - 1).Item(17)

Has to be in my opinion
Dim bytBLOBData() As Byte = _
Ctype(dt.Rows(c - 1).Item(17),Byte())

You can try if this was the only error.

I hope this helps?

Cor
 
G

Guest

Dear Cor Ligthert:
This code only gets the last record always. what I need is to get every
record or rows from the database with columns with the images. Thanks anyway!
Arnold
 
C

Cor Ligthert

Arnold,
This code only gets the last record always. what I need is to get every
record or rows from the database with columns with the images. Thanks
anyway!
Arnold

That is in the structure of your code, before my correction you got nothing
you told.

I told I would take them one by one, however it is better that you look for
yourself first.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top