| | |
import image to db
Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
i created a sql database with table land.
columns;
LandID int PK
LandCodeID int
LandName nvarchar(100)
LandFlag image Allow Nulls
ive created a dataset in my solution.
from my Data Sources i can drag & drop the table Land to my Form1 as DataGridView. it puts all the columns above on my form. im able to update/add/delete Lands except the flag. i want to double click on the landFlagPictureBox so i can select the jpg image to save it in my database. can anyone help me out?
thanx in advance
columns;
LandID int PK
LandCodeID int
LandName nvarchar(100)
LandFlag image Allow Nulls
ive created a dataset in my solution.
from my Data Sources i can drag & drop the table Land to my Form1 as DataGridView. it puts all the columns above on my form. im able to update/add/delete Lands except the flag. i want to double click on the landFlagPictureBox so i can select the jpg image to save it in my database. can anyone help me out?
thanx in advance
Last edited by karabela; Aug 4th, 2008 at 1:07 pm.
•
•
Join Date: Jun 2006
Posts: 37
Reputation:
Solved Threads: 2
Hey, try this one, I just learn if from http://www.codeproject.com/KB/cs/upl..._DataBase.aspx
C# Syntax (Toggle Plain Text)
Stream streamImage=file1.PostedFile.InputStream; int imageLenght=file1.PostedFile.ContentLength; string strType=file1.PostedFile.ContentType; string strType1=file1.Type; string strName=txtName.Text; Byte[] imgData = new byte[imageLenght]; int n = streamImage.Read(imgData,0,imageLenght); int result = saveImage(strName,imgData,strType); private int saveImage(string strName,byte[] imgData,string strType) { int return1=0; try { SqlCommand cmd= new SqlCommand("INSERT INTO image1(id,imageLenght,imgtype,bytles) values (@id,@imageLenght,@imgtype,@bytles)", con); cmd.Parameters.Add("@id", SqlDbType.VarChar).Value = strName; cmd.Parameters.Add("@imageLenght", SqlDbType.BigInt).Value = imgData.Length; cmd.Parameters.Add("@imgtype", SqlDbType.VarChar,6).Value= strType; cmd.Parameters.Add("@bytles", SqlDbType.Image).Value = imgData; con.Open(); return1 = cmd.ExecuteNonQuery(); con.Close(); } catch(Exception ex) { Response.Write(ex.Message); } return return 1; } finally { con.Close(); }
Last edited by Tekmaven; Aug 8th, 2008 at 4:43 pm. Reason: Code tags
![]() |
Similar Threads
- Paste a image into another (Python)
- Putting an image into a Tkinter thingy (Python)
- Image and ImageTk weirdness (Python)
- Image handling in Adobe (Graphics and Multimedia)
- Tkinter Image Problem (Python)
- Doubling the size of an image (Python)
Other Threads in the C# Forum
- Previous Thread: compare files in c#
- Next Thread: how to extract substring from a string?
| Thread Tools | Search this Thread |
.net access algorithm array asp.net bitmap box broadcast c# check checkbox client combobox control conversion csharp database datagrid datagridview dataset datetime dbconnection decryption degrees design developer draganddrop drawing encryption enum eventhandlers excel file firefox focus form format forms function gdi+ grantorrevokepermissionthroughc#.net hospitalmanagementsystem image input install interface java libraries list loop marshalbyrefobject math mouseclick movingimage mysql netcfsvcutil.exe numeric operator path photoshop php picturebox pixelinversion platform polynomial post programming properties radians read regex remote remoting richtextbox server sleep socket sql statistics string stringformatting study system.servicemodel table tcpclientchannel text textbox thread time timer update usb usercontrol validation visualstudio webbrowser winforms wpf wpfc# xml





