I have a column, of data type image, in a SQL table that I'm trying to
dump to a windows form control.
Does anyone have an example of this code and what control I would use
on the form?
-BJ 7 1500
CODE NOT WORKING
Ok from the example I was able to come up with the following code and I
get this error:
ERROR =
'System.ArgimentException' occured in system.drawing.dll
Invalid parameter used
CODE =
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.Drawing.Imaging
Public Class Form1
Inherits System.Windows.Forms.Form
Dim cn As SqlConnection = New
SqlConnection("DATABASE=MyDB;SERVER=MyServer;USER
ID=Bryan;PASSWORD=hertrim")
#Region " Windows Form Designer generated code "
#End Region
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim cmd As SqlCommand = New SqlCommand("SELECT BlobCol FROM
MySQLTable", cn)
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim ds As DataSet = New DataSet
Dim c As Integer
da.Fill(ds, "dsTable")
c = ds.Tables("dsTable").Rows.Count
If c > 0 Then
Dim bytBLOBData() As Byte = ds.Tables("dsTable").Rows(c -
1)("BlobCol")
Dim stmBLOBData As New MemoryStream(bytBLOBData)
PBOX.Image = Image.FromStream(stmBLOBData)
End If
MsgBox("Image retrieved")
ds = Nothing
da = Nothing
cn.Close()
cn = Nothing
End Sub
End Class
Everthing works except the line where I assign the image to the
Picturebox.Image property. I take an invalid parm exception. See code
below. As a note, I was able to dump contents to a data file, but I
don't want to dump to a file and then turn around and post to the form.
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim sqlcmd As New SqlCommand("SELECT ImageField FROM Mydb",
conn)
Dim da As New SqlDataAdapter
Dim ds As New DataSet
Dim ms As New MemoryStream
Dim bytImage() As Byte
da.SelectCommand = sqlcmd
da.Fill(ds, "ByteTbl")
bytImage = CType(ds.Tables("ByteTbl").Rows(0)(0), Byte())
ms = New MemoryStream(bytImage)
Me.PBOX.Image = Image.FromStream(ms)
conn.Close()
conn = Nothing
sqlcmd = Nothing
da = Nothing
ds = Nothing
ms = Nothing
bytImage = Nothing
End Sub
BJ,
Are you sure that you have a table in your database Mydb which you name in
your dataset suddenly ByteTbl.
As well (not the reason that it is not working). Why do you do all those
crazy setting to nothing, it does nothing beside processing some code? All
those objects go automaticly out of scope in that procedure.
I hope this helps,
Cor
The table connection is working. I tested the connection / fill /
table (ByteTbl) content by dumping a couple of other columns.
The content isn't the problem, because I can dump the contents to a
flat file and interrogate it. By the way the contents of each data
cell is a Crystal Reports template. Every example I've seen about
dumping an image column to a win form Picture Box uses the above code.
So I'm going to try to store my own jpeg images to a table and use the
code above to pull it out again. If that works, then the Picture Box
control probably has a problem storing that kind of data.
Those crazy lines that set my objects to nothing is (1) by habit from
my C/C++/Java days where is was always good practice to do your our
house keeping; (2) do you really trust MS to do all your housekeeping?
Have you ever known a product to have a memory leak? Basically, the
code does hurt, for ME its just a good programming habit.
BJ
That good programming habit is as good as this
Sub A
dim a as integer
...
a = 0
End sub
However feel free to do this kind of code.
It is especially useful if you are paid per line.
And if it gives errors, than buy another compiler, if this is not done by
your compiler than it is really a bad product, in vendors who have these
compilers tell of course told that it is good practise.
Just my idea
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: dave |
last post by:
Hello there,
I am at my wit's end ! I have used the following script succesfully to
upload an image to my web space. But what I really want to be able to do is
to update an existing record in a...
|
by: Ravi Tallury |
last post by:
Hi
We are having issues with our application, certain portions of it stop
responding while the rest of the application is fine. I am attaching
the Java Core dump. If someone can let me know what...
|
by: Matt |
last post by:
I want to know what is Hex Dump? I tried to search in google but
didn't get useful results. I know it is the hexademical representation
of something. But I don't know what is something? From C...
|
by: John Thompson |
last post by:
We're sooo close. When we load the page to upload the image, all of
the prms go through except the binary image data. Using SQL server
with the data type set to "image".
Please help!
Thanks-...
|
by: Stan Sainte-Rose |
last post by:
Hi,
What is the better way to save image into a database ?
Just save the path into a field or save the image itself ?
I have 20 000 images (~ 10/12 Ko per image ) to save.
Stan
|
by: Kim |
last post by:
Random image downloader for specified newsgroup. Hi I'm writing a small script that will download random images from a specified newsgroup. I've imported yenc into the script but I can't open the...
|
by: Peter |
last post by:
I have a problem with a page show_image.asp that returns a jpg image under
Windows XP Pro SP2. The page sets content type as:
Response.ContentType = "image/jpg"
While this works perfectly fine...
|
by: Aidan |
last post by:
Hi,
I'm having a bit of trouble with a python script I wrote, though I'm not
sure if it's related directly to python, or one of the other software
packages...
The situation is that I'm trying...
|
by: premprakashbhati |
last post by:
hi, good evening..
i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button()
here is the code ...its work fine...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |