Net-informations.com
SiteMap  | About    

ASP.NET Image to Database

A data type is an attribute that specifies the type of data that the object can hold. An Image is a Datatype in SQL Server that stores variable length binary data from 0 through 2A31-1 (2,147,483,647) bytes.

The following sql script help you to create a table with Image Datatype column.

  CREATE TABLE [dbo].[imagestore](
	[id] [int] NULL,
	[img] [image] NULL

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

The above script will create a table named as imagestore and define two columns , first column is id ,an integer datatype and second column is image, an image(img) datatype.

The following ASP.NET program upload an image file and saved it to local system and later that image will insert into the database.

Default.aspx

  

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
		<asp:FileUpload ID="FileUpload1" runat="server" />
		<br />
		<br />
		<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Upload"
			Width="123px" />
		<br />
		<br />
		<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
	</div>
	</form>
</body>
</html>


Click the following links to see full source code

C# Source Code
VB.NET Source Code
default.aspx.cs
default.aspx.vb





net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.