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