Solved

Import Image into SQL Image Field Vb.Net

Posted on 2009-05-15
5
336 Views
Last Modified: 2012-05-07
Hi,

I'm Importing an XML file into SQL but one of the elements in the XML file contains an image and I'm wondering how to do that.  Here's some of my code, although it's wrong but I'm just wondering how to handle the image.

Thanks

Lee
Dim cm As SqlCommand
Dim objCon As SqlConnection = New SqlConnection(sConnection)
cm = New SqlCommand("usp_addXML", objCon)
cm.CommandType = CommandType.StoredProcedure
 
Dim pID As SqlParameter = New SqlParameter("@ID", SqlDbType.BigInt, 100)
Dim pPhotograph As SqlParameter = New SqlParameter("@Photograph", SqlDbType.Image)
 
While myNodeText.MoveNext()
 
    Select Case myNodeText.Current.Name
        Case "ID"
            pID.Value = iCount
            cm.Parameters.Add(pID)
        Case "Photograph"
            pPhotograph.Value = myNodeText.Current.Value
            cm.Parameters.Add(pPhotograph)
    End Select
 
The line pOffencePhotograph.Value = myNodeText.Current.Value is obviously trying to pass a string, so I need to convert it to an image.  Thanks in advance.

Open in new window

0
Comment
Question by:lee_murphy
  • 3
  • 2
5 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 24394786
Save An Image Into SQL Server 2000 Database
http://www.codeproject.com/KB/web-image/PicManager.aspx

HOWTO: Read and write images from a database using SQL Server
http://www.atalasoft.com/KB/Article.aspx?id=10018
0
 

Author Comment

by:lee_murphy
ID: 24394891
Thanks Dhaest, the first example I beleive requires me to create a file from the data first.  The second doesn't but that requires me to purchase something.  Is there a way of importing it without saving it to an external file, and without buying some add-on?
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 24394905
>> without saving it to an external

I have never seen it before (and saw the same question alot)
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 125 total points
ID: 24394923
Or do you mean without an external application (like atalasoft)

CodeSnip: How to Read/Write an Image to Database in Binary Format
http://aspalliance.com/1083_codesnip_how_to_readwrite_an_image_to_database_in_binary_format

Get Image from DB table and show it
http://www.codeproject.com/KB/database/images2db.aspx

Save/Retrieve Image From SQL Server Database Using Ado 2.5 Stream Object
http://www.freevbcode.com/ShowCode.Asp?ID=1802

Other usefull resources
http://www.stardeveloper.com/articles/display.html?article=2001033101&page=1 
http://www.carobit.com/ShowThread/Visual%20Basic/20021128112520Rem.html 
0
 

Author Closing Comment

by:lee_murphy
ID: 31581885
Got it to work saving to a file and then importing that.  Thanks for your help
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question