473,320 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Inserting image into SQL database

OuTCasT
374 256MB
Can someone please tell me how to save an image into an SQL DATABASE ?
never done it before and want to try it out.
using web forms.
Jan 31 '08 #1
6 3501
debasisdas
8,127 Expert 4TB
1.Try to use LOB as field type in database.
2.read the image file.
3.convert the file to binary stream .
4 store in database.
Jan 31 '08 #2
OuTCasT
374 256MB
1.Try to use LOB as field type in database.
2.read the image file.
3.convert the file to binary stream .
4 store in database.

i have no idea where to start
lol
Jan 31 '08 #3
debasisdas
8,127 Expert 4TB
i have no idea where to start
lol
There is nothing to lol here.

Just follow the steps as suggested in previous post.
Jan 31 '08 #4
dwadish
129 100+
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. Atalasoft dotImage has streaming capabilities that can be used jointly with ADO.NET to read and write images directly to a database without saving to a temporary file. The following code snippets demonstrates this in C# and VB.NET.
  4.  
  5. Write to a Database
  6. C#
  7. private void SaveToSqlDatabase(AtalaImage image){SqlConnection myConnection = null;    try    {        // Save image to byte array.        byte[] imagedata = image.ToByteArray(new Atalasoft.Imaging.Codec.JpegEncoder(75));                // Create the SQL statement to add the image data.        myConnection = new SqlConnection(CONNECTION_STRING);        SqlCommand myCommand = new SqlCommand                ("INSERT INTO Atalasoft_Image_Database (Caption, ImageData) VALUES ('" + txtCaption.Text + "', @Image)", myConnection);        SqlParameter myParameter = new SqlParameter("@Image", SqlDbType.Image, imagedata.Length);        myParameter.Value = imagedata;        myCommand.Parameters.Add(myParameter);                // Open the connection and execture the statement.        myConnection.Open();        myCommand.ExecuteNonQuery();    }    finally    {        myConnection.Close();    }}Visual Basic.NET
  8. Private Sub SaveToSqlDatabase(ByVal image As AtalaImage)    Dim myConnection As SqlConnection = Nothing    Try        ' Save image to byte array.        Dim imagedata() As Byte = image.ToByteArray(New Atalasoft.Imaging.Codec.JpegEncoder(75))                ' Create the SQL statement to add the image data.        myConnection = New SqlConnection(CONNECTION_STRING)        Dim myCommand As SqlCommand = New SqlCommand                ("INSERT INTO Atalasoft_Image_Database (Caption, ImageData) VALUES ('" + txtCaption.Text + "', @Image)", myConnection)        Dim myParameter As SqlParameter = New SqlParameter("@Image", SqlDbType.Image, imagedata.Length)        myParameter.Value = imagedata        myCommand.Parameters.Add(myParameter)                ' Open the connection and execture the statement.        myConnection.Open()        myCommand.ExecuteNonQuery()    Finally        myConnection.Close()    End TryEnd SubRead from a Database
  9. C#
  10. private AtalaImage OpenFromSqlDatabase(){    SqlConnection myConnection = null;    try    {        // Establish connection and SELECT statement.        myConnection = new SqlConnection(CONNECTION_STRING);        SqlCommand myCommand = new SqlCommand                ("SELECT ImageData FROM Atalasoft_Image_Database WHERE Caption = '" + txtCaption.Text + "'", myConnection);        myConnection.Open();                // Get the image from the database.        byte[] imagedata = (byte[])myCommand.ExecuteScalar();        if (imagedata != null)        {            AtalaImage image = AtalaImage.FromByteArray(imagedata);            return image;        }        else        {            MessageBox.Show("Image does not exist in database.");            return null;        }    }    finally    {        myConnection.Close();    }}Visual Basic .NET
  11. Private Function OpenFromSqlDatabase() As AtalaImage    Dim myConnection As SqlConnection = Nothing    Try        ' Establish connection and SELECT statement.        myConnection = New SqlConnection(CONNECTION_STRING)        Dim myCommand As SqlCommand = New SqlCommand                ("SELECT ImageData FROM Atalasoft_Image_Database WHERE Caption = '" + txtCaption.Text + "'", myConnection)        myConnection.Open()                ' Get the image from the database.        Dim imagedata() As Byte = CType(myCommand.ExecuteScalar(), Byte())        If (Not imagedata Is Nothing) Then            Dim image As AtalaImage = AtalaImage.FromByteArray(imagedata)            Return image        Else            MessageBox.Show("Image does not exist in database.")            Return Nothing        End If    Finally        myConnection.Close()    End TryEnd Function
  12.  
Just use it
Jan 31 '08 #5
OuTCasT
374 256MB
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. Atalasoft dotImage has streaming capabilities that can be used jointly with ADO.NET to read and write images directly to a database without saving to a temporary file. The following code snippets demonstrates this in C# and VB.NET.
  4.  
  5. Write to a Database
  6. C#
  7. private void SaveToSqlDatabase(AtalaImage image){SqlConnection myConnection = null;    try    {        // Save image to byte array.        byte[] imagedata = image.ToByteArray(new Atalasoft.Imaging.Codec.JpegEncoder(75));                // Create the SQL statement to add the image data.        myConnection = new SqlConnection(CONNECTION_STRING);        SqlCommand myCommand = new SqlCommand                ("INSERT INTO Atalasoft_Image_Database (Caption, ImageData) VALUES ('" + txtCaption.Text + "', @Image)", myConnection);        SqlParameter myParameter = new SqlParameter("@Image", SqlDbType.Image, imagedata.Length);        myParameter.Value = imagedata;        myCommand.Parameters.Add(myParameter);                // Open the connection and execture the statement.        myConnection.Open();        myCommand.ExecuteNonQuery();    }    finally    {        myConnection.Close();    }}Visual Basic.NET
  8. Private Sub SaveToSqlDatabase(ByVal image As AtalaImage)    Dim myConnection As SqlConnection = Nothing    Try        ' Save image to byte array.        Dim imagedata() As Byte = image.ToByteArray(New Atalasoft.Imaging.Codec.JpegEncoder(75))                ' Create the SQL statement to add the image data.        myConnection = New SqlConnection(CONNECTION_STRING)        Dim myCommand As SqlCommand = New SqlCommand                ("INSERT INTO Atalasoft_Image_Database (Caption, ImageData) VALUES ('" + txtCaption.Text + "', @Image)", myConnection)        Dim myParameter As SqlParameter = New SqlParameter("@Image", SqlDbType.Image, imagedata.Length)        myParameter.Value = imagedata        myCommand.Parameters.Add(myParameter)                ' Open the connection and execture the statement.        myConnection.Open()        myCommand.ExecuteNonQuery()    Finally        myConnection.Close()    End TryEnd SubRead from a Database
  9. C#
  10. private AtalaImage OpenFromSqlDatabase(){    SqlConnection myConnection = null;    try    {        // Establish connection and SELECT statement.        myConnection = new SqlConnection(CONNECTION_STRING);        SqlCommand myCommand = new SqlCommand                ("SELECT ImageData FROM Atalasoft_Image_Database WHERE Caption = '" + txtCaption.Text + "'", myConnection);        myConnection.Open();                // Get the image from the database.        byte[] imagedata = (byte[])myCommand.ExecuteScalar();        if (imagedata != null)        {            AtalaImage image = AtalaImage.FromByteArray(imagedata);            return image;        }        else        {            MessageBox.Show("Image does not exist in database.");            return null;        }    }    finally    {        myConnection.Close();    }}Visual Basic .NET
  11. Private Function OpenFromSqlDatabase() As AtalaImage    Dim myConnection As SqlConnection = Nothing    Try        ' Establish connection and SELECT statement.        myConnection = New SqlConnection(CONNECTION_STRING)        Dim myCommand As SqlCommand = New SqlCommand                ("SELECT ImageData FROM Atalasoft_Image_Database WHERE Caption = '" + txtCaption.Text + "'", myConnection)        myConnection.Open()                ' Get the image from the database.        Dim imagedata() As Byte = CType(myCommand.ExecuteScalar(), Byte())        If (Not imagedata Is Nothing) Then            Dim image As AtalaImage = AtalaImage.FromByteArray(imagedata)            Return image        Else            MessageBox.Show("Image does not exist in database.")            Return Nothing        End If    Finally        myConnection.Close()    End TryEnd Function
  12.  
Just use it
THanks for the code, what imports are needed for atala image ?
Feb 1 '08 #6
OuTCasT
374 256MB
THanks for the code, what imports are needed for atala image ?
Went onto the website.....no worries
Feb 1 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mat | last post by:
Hi, I have a system that uploads images as BLOBs in a database. I also have a function that I use to resize uploaded images before saving as files. I would like to combine these two by resising...
1
by: mar10a | last post by:
I am trying to insert a .gif. file into an Access report - using Insert Picture. The original image is 8X11, but access changes the size to 4X6.5. When I change the size of the image in access...
1
by: Daniel | last post by:
I have looked everywhere on the web for an answer to this and the only thing I can find is converting the image format when the file is present on the local filesystem. What I want to do is use a...
2
by: neuneudr | last post by:
Hi all, I've been trying JavaScript a little bit. I beginned by changing an image using a very simple: document.getElementById(...).src="new image" Which worked fine. However this does...
10
by: Roger Withnell | last post by:
I'm using ASP, VBScript and SQL Server. I'm also using UTF-8 character set and so my codepage is 65001 and SQL Server datatype nvarchar. I can insert unicode characters correctly into the...
1
by: developers | last post by:
Hello Every One , I need Help in inserting the user image in my data base. but unfortunatly I don't know how.I'm using asp with sql server. I tried to insert the image and i geuss it worked.for...
3
by: gazanfar | last post by:
Hi, guys hope fine all.... I have problem in inserting image in SQL SERVER 2000 database by program of VB.so give me some source code ????? if you can..................... and second is I...
5
by: Dionysus | last post by:
Using (or massacring) PHP, I'm trying to read the contents of a text field in a database (magazine article) and then break it into lines and insert an image file ever 3-4 lines if the image is...
3
by: lmeeson | last post by:
hi guys, I am totally new to coding so please bare with me. I have a file upload field in a form on a PHP page for users to upload pictures, i also have the following fields in my MySQL database ...
4
by: ghjk | last post by:
I wan to add some data using php page to mysql db. But I got the error saying "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.