I'm attempting to retrieve a bitmap from an image field in SQL Server 2005
using Visual Studio 2005 C#. I then want to load the bitmap into a
picturebox. When I run the following code, I get the error message:
Parameter is no valid.
Debugging shows that the Image.FromStrea m(ms) statement is the culprit.
Anyone know what I'm doing wrong?
-----------------------------------------
using (SqlConnection sqlConn = new SqlConnection(b uilder.Connecti onString))
{
sqlConn.Open();
SqlDataAdapter sql = new SqlDataAdapter(
"SELECT Picture FROM Pictures WHERE Pictures.CardID =5", sqlConn);
DataSet ds1 = new DataSet();
sql.Fill(ds1, "Pictures") ;
DataRow dr = ds1.Tables["Pictures"].Rows[0];
byte[] result = (byte[])dr["Picture"];
int ArraySize = result.GetUpper Bound(0);
MemoryStream ms = new MemoryStream(re sult, 0, ArraySize);
pictureBox1.Ima ge = Image.FromStrea m(ms);
sqlConn.Close() ;
} 1 11590
Hi wsclichtman,
I'm guessing SQL Server 2005 uses the same image header as 2000, so you need to remove the first 80(?) bytes from the stream before creating a Bitmap out of it.
On Tue, 20 Sep 2005 02:23:02 +0200, wschlichtman <ws**********@d iscussions.micr osoft.com> wrote: I'm attempting to retrieve a bitmap from an image field in SQL Server 2005 using Visual Studio 2005 C#. I then want to load the bitmap into a picturebox. When I run the following code, I get the error message:
Parameter is no valid.
Debugging shows that the Image.FromStrea m(ms) statement is the culprit.
Anyone know what I'm doing wrong?
-----------------------------------------
using (SqlConnection sqlConn = new SqlConnection(b uilder.Connecti onString)) { sqlConn.Open(); SqlDataAdapter sql = new SqlDataAdapter( "SELECT Picture FROM Pictures WHERE Pictures.CardID =5", sqlConn); DataSet ds1 = new DataSet(); sql.Fill(ds1, "Pictures") ; DataRow dr = ds1.Tables["Pictures"].Rows[0];
byte[] result = (byte[])dr["Picture"]; int ArraySize = result.GetUpper Bound(0);
MemoryStream ms = new MemoryStream(re sult, 0, ArraySize); pictureBox1.Ima ge = Image.FromStrea m(ms); sqlConn.Close() ; }
--
Happy coding!
Morten Wennevik [C# MVP] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Lindsey Howell |
last post by:
Hello,
I've encountered a problem when trying to display BLOB images from a SQL
database using VB.NET. This is the code which generates the error:
Dim mySqlConnection As SqlConnection = New
SqlConnection(connectionString)
Dim mySqlCommand As SqlCommand = New SqlCommand(queryString,
mySqlConnection)
Dim ms as MemoryStream = New MemoryStream
|
by: Peter Proost |
last post by:
Hi I got this code to read in a file to the database, if use it to save a
image from a picturebox to the database it works ok, but now I use it to
directly save a file to the database without loading the image in a
picturebox and it also works but there's a black line drawn from
coordinates(0,0) to coordinates(image.width,0) when I look at the blob field
using crystal reports 9, the line normaly isn't there.What am I doing wrong?
Dim ms...
|
by: The Confessor |
last post by:
(ellipses in place of code sections which do not deviate from defaults)
Private Sub Form_Main_Load(...) Handles MyBase.Load
For A = 0 To 16
For B = 0 To 14
PictureBox_MapEditor_Map.CreateGraphics.DrawImage
(System.Drawing.Image.FromFile("C:\The RPG Project\Test 2.bmp"), A * 40,
B * 40)
Next
Next
|
by: Hrvoje Voda |
last post by:
I'm using this code to get a blob from sql database, and put it into
picturebox, but I don't know how to load it into picturebox.
Code:
sqlConnection.Open();
System.Data.SqlClient.SqlCommand LogoBLOBSelect = new
System.Data.SqlClient.SqlCommand();
|
by: Mark |
last post by:
I have a VB 6 program that I have saved an audio file to using DAO and the
appendchunk as is shown at http://support.microsoft.com/kb/103257/EN-US/. ; I
have it working fine in that app (it saves to an access database and I can
save the data back to a file using getchunk and everything works correctly).
The issue is that I am now trying to access the database in VB.NET 2003
through an OleDBDataAdapter (Jet 4.0 connection) and can't get it...
| |
by: Marcus Kwok |
last post by:
I have written a class (Windows Form) in Managed C++ that accepts an
array of image filenames and will display them sequentially. All images
will be the same size. I got it to work, but I know something is not
right because of the way I am using Application::DoEvents() (ref:
http://www.codinghorror.com/blog/archives/000159.html and
http://www.codinghorror.com/blog/archives/000370.html ), along with the
fact that I get a crash when I try...
|
by: CD |
last post by:
An application is logging faxes sent in SQL2000 image column type. I have
found code on the net but what it is doing is prompting to save to local
which is fine for single page image. Not good for multiple page faxes. I
have not been able to locate an example to load in the browser or how to
handle multiple image in the one column.
1) Ideally it would be nice to display back in the browser since some may be
multiple images. I am not...
|
by: Vinciz |
last post by:
hi guys... im new in java and i would love to learn some of these...
basically i got a sample code to retrieve the blob from the mysql.
however, i dont really know what to do with these retrieved byte/binary data as i got no idea on how to save them in our pc. For this situation, what i need to do is give the byte/binary data an extension (retrieved from another field in the table) in order to revert back to the original data i had in the...
|
by: Usenet User |
last post by:
..NET 1.1/2.0
I have a need to display high-resolution scrollable images in a .NET
application (Windows Forms). One well known solution is to create a
Panel with AutoScroll set to "true" and then add a PictureBox or
another Panel to it, that is used to display the image.
The above approach works, however, to my surprise, .NET GDI+-based
graphics are not really hi-res friendly.
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
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...
| |