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.
6 3501
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.
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
i have no idea where to start
lol
There is nothing to lol here.
Just follow the steps as suggested in previous post.
-
-
-
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.
-
-
Write to a Database
-
C#
-
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
-
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
-
C#
-
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
-
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
-
Just use it
-
-
-
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.
-
-
Write to a Database
-
C#
-
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
-
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
-
C#
-
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
-
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
-
Just use it
THanks for the code, what imports are needed for atala image ?
THanks for the code, what imports are needed for atala image ?
Went onto the website.....no worries
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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 ...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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...
| |