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 1518
CODE NOT WORKING
Ok from the example I was able to come up with the following code and I
get this error:
ERROR =
'System.Argimen tException' occured in system.drawing. dll
Invalid parameter used
CODE =
Imports System.Data
Imports System.Data.Sql Client
Imports System.IO
Imports System.Drawing. Imaging
Public Class Form1
Inherits System.Windows. Forms.Form
Dim cn As SqlConnection = New
SqlConnection(" DATABASE=MyDB;S ERVER=MyServer; USER
ID=Bryan;PASSWO RD=hertrim")
#Region " Windows Form Designer generated code "
#End Region
Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim cmd As SqlCommand = New SqlCommand("SEL ECT 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("dsTa ble").Rows.Coun t
If c > 0 Then
Dim bytBLOBData() As Byte = ds.Tables("dsTa ble").Rows(c -
1)("BlobCol")
Dim stmBLOBData As New MemoryStream(by tBLOBData)
PBOX.Image = Image.FromStrea m(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.Imag e 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(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim sqlcmd As New SqlCommand("SEL ECT ImageField FROM Mydb",
conn)
Dim da As New SqlDataAdapter
Dim ds As New DataSet
Dim ms As New MemoryStream
Dim bytImage() As Byte
da.SelectComman d = sqlcmd
da.Fill(ds, "ByteTbl")
bytImage = CType(ds.Tables ("ByteTbl").Row s(0)(0), Byte())
ms = New MemoryStream(by tImage)
Me.PBOX.Image = Image.FromStrea m(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 table in MySQL with the path & filename to
the image.
I have successfully uploaded and performed an update query on the database,
but the problem I have is I cannot retain the primary key field in a
variable which is then used in a SQL update...
|
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 the issue is.
Thanks
Ravi
|
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 programmer's
perspective,
I always hear this term. But when do we need to use hex dump? what's
the importances of hex dump?
please advise. thanks!!
|
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-
John
|
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 image or save it. This is my first script so be gentle!
Heres the script
####random group downloader####
import nntplib
import string, random
import mimetools
import StringIO
|
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 on most machines, on some machines I
experience this problem:
When loading the page a window pops up that asks if I want to open the
document show_page.asp. When I click "Open" Interdev pops up and opens up a
|
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 to create a system backup script that
creates an image of the system, filters the output though gzip, and then
uploads the data (via ftp) to a remote site.
|
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 when iam using a normal web page... but can't in content page....
Code in Master Page
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="submaster.master.cs" Inherits="submaster" %>
<%@ Register Assembly="AjaxControlToolkit"...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |