472,969 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,969 software developers and data experts.

Error in loading images from database "Invalid Parameter Used"

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("connectionStrin g")
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

Nov 21 '05 #1
3 2530
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

Nov 21 '05 #2
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

"Cor Ligthert" wrote:
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

Nov 21 '05 #3
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
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: vincent wehren | last post by:
Hi, Trying to grasp Py_NewInterpreter()in a simple app embedding Python, I was wondering why the following gives me an error: int main() { PyThreadState *tstate; Py_Initialize();
3
by: Stephen Poley | last post by:
Could some kind soul explain the errors and warnings that the W3C CSS validator generates for page: http://www.atlis.nl/testsite/nl/ Results at: http://tinyurl.com/5pxqx The error "Invalid...
9
by: Wally | last post by:
I am trying to display images from an Access 2000 database and I get an error "Invalid Parameter Used" when I execute the code line "picBLOB.Image = Image.FromStream(stmBLOBData)" in my Visual...
7
by: cnu | last post by:
Hi I have to write images(.gif/.bmp/.jpg/.ico), to db and read them. Uploading images to db works fine for me. Reading from db to byte is also ok. But, when I try to display them in my form...
0
by: Simon Harris | last post by:
I'm trying to access a password protected web service. My code is as follows: Dim BS7666 As New bs7666.BS7666 'New instance of my web service Dim CredCache As CredentialCache = New...
6
by: Patrick Dugan | last post by:
Hello, I'm trying to load different images (icons) into a PictureBox1.Image. The first image loads just fine, but the second image always returns the error "Invalid property used." It doesn't...
4
by: escristian | last post by:
Hello. I'm trying to create an Image so I use something like this: Image newImage = Image.FromFile(filename); Now when it's a bmp file and certain .gif files it gives me an exception that...
1
by: imranabdulaziz | last post by:
Dear All, I am using sql2005. i am writing stored procedure to save various master data . I recognize master by @type (input verible) and assign it to @mst veriable then based on @mst no I...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.