Sei sulla pagina 1di 19

Writing pictures, pdf and other byte arrays to SQL Server in C#.

Net
Reading and displaying pictures, pdf and other byte arrays to Web Pages in C#.Net
This project is created with Visual Studio 2008, using C# to create a Web application.

This project consists of :


Default.aspx – upload and invoke the page, BinaryViewer.aspx to see the stored contents
Default.aspx.cs – code behind
Thumbnail.ashx – Web handler to direct the byte[] image stream
DataAccess.cs – Separate connectivity and the clients
Web.config – control the connection string used for an included SQL Server database, ImageStore.mdf
BinaryViewer.aspx
BinaryViewer.aspx.cs
ImageStore.mdf – Second database, just to show you can have your SQL Server inside the application’
project or you can access an independent SQL Server (as you can see in DataAccess.cs).

SQL Script.sql - Script to create the database, table and stored procedure

This project saves jpgs, bmps, pdfs, etc. to a SQL Server Images table. The script is also included from
the original project downloaded some time ago from the Web. The repeater that displays the list of
items in the table on Default.aspx is not necessary for the purpose of this application. What is usually
desired is to have a pdf store for such things as operating procedures or references that can be accessed
and viewed through portal web sites or maintenance applications in a distributed Web. Obviously the
approach here will not show the pdf file in the image box, but as illustrated, images do display as the
thumbnails.

I posted this as a reference for anyone to find a complete example of what one would expect for a Web
application that saves image/pdf data to the server and expects to read it back to a Web page. Having
images, pdfs, Word, Powerpoint, Excel and other document formats in a database instead of external
documents lends extreme flexibility to the search process of the users. Replacements of documents are
a snap as opposed to writing over documents that are stored in folders on the Web site. Physical
storage in folders presents access permissions issues that are easily handled with SQL Server.

Although this example is for SQL Server, it can apply just a well to Microsoft Access (although this is not
highly recommend, but if your Web server is without SQL Server, it is an alternate approach), MySQL, or
Oracle. In each case, you will need to implement the appropriate framework for the database (using
System.Data.SqlClient; for SQL Server, using System.Data.OleDb; or .Odbc for
ODBC connectivity through an appropriate driver to your database).

Good luck. There are many other examples of this in Google or Bing.
You will need to enter the ID number for each record and select the appropriate
Response.ContentType for that record. Obviously your production application will have all the
features built-in so the user will not have to determine these details. So entering 1 and selecting
image/GIF will produce the following web page:
If, instead, the user enters the id of 7 and selects the application/PDF Response.ContentType this
page appears, a pdf sheet music score that was saved earlier to SQL Server:
Here is the client source for the Default.aspx page that provides the ability to upload into your SQL Serve
database:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 runat="server">
<title>Image Upload to DB</title>
</head>
<body style="font-family: Verdana; font-size: 10pt">
<div style="padding: 10px">
<form id="form1" runat="server">
<div style="border:solid thick red">
Enter ID (1, 2, or a valid record id in the Images table:<asp:TextBox ID="txtImageId"
runat="server"></asp:TextBox>
<asp:ListBox ID="listResponseTypes" runat="server"
onselectedindexchanged="listResponseTypes_SelectedIndexChanged">
<asp:ListItem value='application/PDF'>application/PDF</asp:ListItem>
<asp:ListItem value='application/PDF'>application/vnd.ms-excel</asp:ListItem>
<asp:ListItem value='application/PDF'>application/msword</asp:ListItem>
<asp:ListItem value='application/PDF'>application/vnd.ms-
powerpoint</asp:ListItem>
<asp:ListItem value='application/PDF'>application/zip</asp:ListItem>
<asp:ListItem value='image/GIF'>image/gif</asp:ListItem>
<asp:ListItem value='image/GIF'>image/vnd.microsoft.icon</asp:ListItem>
<asp:ListItem value='mage/JPEG'>image/jpeg</asp:ListItem>
<asp:ListItem value='text/HTML'>text/html</asp:ListItem>
</asp:ListBox>
<br /><asp:Button ID="btnSubmitImageId" runat="server" Text="View Saved Byte Array"
onclick="btnSubmitImageId_Click" style="height: 26px" />
</div>

<div>Enter a description for image<br /></div>


<div><asp:TextBox ID="Description" runat="server" style="width: 500px;"
EnableViewState="false"/><br /><br /></div>
<div>Browse for your file (jpg only)<br /></div>
<div><asp:FileUpload ID="fileUpload" runat="server" style="width: 350px"/><br
/></div>
<p><asp:Button ID="Submit" runat="server" Text="Upload" onclick="Submit_Click" /></p>
<p />
<div>Images in Database<br /><br /></div>
<asp:Repeater ID="repImages" runat="server" Visible="true"
onitemdatabound="repImages_ItemDataBound">
<ItemTemplate>
<div><asp:Image ID="imageThumb" runat="server" Visible="false" /></div>
<div><asp:Label ID="labelDescription" runat="server" Visible="false" /></div>
<br /><br />
</ItemTemplate>
</asp:Repeater>
</form>
</div>
</body>
</html>
Here is the C# code-behind for Default.aspx:
using System;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

// bind the list of images from the database


if (!IsPostBack)
repImages.DataSource = DataAccess.ListImages();

DataBind();
}

protected void Submit_Click(object sender, EventArgs e)


{
if (IsPostBack)
HandleUploadedFile();
}

/// <summary>
/// Method to handle pulling the files from the request and send them to the database
/// </summary>
private void HandleUploadedFile()
{
// get the file instance
HttpPostedFile fi = Request.Files.Get(0);

// get the description


string description = Description.Text;

// create a byte array to store the file bytes


byte[] fileBytes = new byte[fi.ContentLength];

// fill the byte array


using (System.IO.Stream stream = fi.InputStream)
{
stream.Read(fileBytes, 0, fi.ContentLength);
}

// insert the image


DataAccess.InsertImage(description, fileBytes);

// bind the image list


repImages.DataSource = DataAccess.ListImages();
DataBind();

// clean up
Description.Text = "";
fileBytes = null;
}

/// <summary>
/// on each item in the repeater setup the asp controls with some properties
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void repImages_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
// get our object from the datasource
DataAccess.ImageData item = (DataAccess.ImageData)e.Item.DataItem;

// get a reference to our controls in the item template


Image image = (Image)e.Item.FindControl("imageThumb");
Label label = (Label)e.Item.FindControl("labelDescription");

// set the image control properties. This is for the display of all the contents
in thumbnail format.
if (image != null)
{
image.ImageUrl = string.Format("~/Thumbnail.ashx?id={0}", item.ID);
image.AlternateText = item.Description;
image.Visible = true;
}

// set the image title


if (label != null)
{
label.Text = item.Description;
label.Visible = true;
}
}
protected void btnSubmitImageId_Click(object sender, EventArgs e)
{
//Here is where we send the request to view the page with our image data type resolved:
if(this.txtImageId.Text.Trim().Length > 0)
{
Response.Redirect("BinaryViewer.aspx?imageid=" + this.txtImageId.Text.Trim() +
"&contenttype=" +
this.listResponseTypes.Items[listResponseTypes.SelectedIndex].Value.ToString());
}
}
}
This nifty item, Thumbnail.ashx, allows you to create thumbnails and pass the image through it to be resolved as
your database contents. Image types (jpg or bmp) are necessary to be successfully displayed.

<%@ WebHandler Language="C#" Class="Thumbnail" %>


using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Web;

public class Thumbnail : IHttpHandler


{

public void ProcessRequest (HttpContext context)


{
// Set up the response settings
context.Response.ContentType = "image/jpeg";
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.BufferOutput = false;

if (!string.IsNullOrEmpty(context.Request.QueryString["ID"]))
{
// get the id for the image
int id = Convert.ToInt32(context.Request.QueryString["ID"]);

// get the image as a byte array


byte[] imageAsBytes = DataAccess.GetImageByID(id);

// resize the image to a thumb (100)


imageAsBytes = ResizeImageFile(imageAsBytes, 100);

// put the byte array into a stream


Stream stream = new MemoryStream((byte[])imageAsBytes);

// setup the chunking of the image data (good for large images)
int buffersize = 1024 * 16;
byte[] buffer = new byte[buffersize];

// push the bytes to the output stream in chunks


int count = stream.Read(buffer, 0, buffersize);
while (count > 0)
{
context.Response.OutputStream.Write(buffer, 0, count);
count = stream.Read(buffer, 0, buffersize);
}
}
}

public bool IsReusable


{
get { return true; }
}

/// <summary>
/// Resizes an image
/// </summary>
/// <param name="imageFile">the byte array of the file</param>
/// <param name="targetSize">the target size of the file (may affect width or height)
/// depends on orientation of file (landscape or portrait)</param>
/// <returns>Byte array containing the resized file</returns>
private static byte[] ResizeImageFile(byte[] imageFile, int targetSize)
{
using (System.Drawing.Image oldImage =
System.Drawing.Image.FromStream(new MemoryStream(imageFile)))
{
Size newSize = CalculateDimensions(oldImage.Size, targetSize);

using (Bitmap newImage =


new Bitmap(newSize.Width,
newSize.Height, PixelFormat.Format24bppRgb))
{
using (Graphics canvas = Graphics.FromImage(newImage))
{
canvas.SmoothingMode = SmoothingMode.AntiAlias;
canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
canvas.PixelOffsetMode = PixelOffsetMode.HighQuality;
canvas.DrawImage(oldImage,
new Rectangle(new Point(0, 0), newSize));

MemoryStream m = new MemoryStream();


newImage.Save(m, ImageFormat.Jpeg);
return m.GetBuffer();
}
}
}
}

/// <summary>
/// Calculates the new size of the image based on the target size
/// </summary>
/// <param name="oldSize">Is the size of the original file</param>
/// <param name="targetSize">Is the target size of the resized file</param>
/// <returns>The new size</returns>
private static Size CalculateDimensions(Size oldSize, int targetSize)
{
Size newSize = new Size();
if (oldSize.Height > oldSize.Width)
{
newSize.Width =
(int)(oldSize.Width * ((float)targetSize / (float)oldSize.Height));
newSize.Height = targetSize;
}
else
{
newSize.Width = targetSize;
newSize.Height =
(int)(oldSize.Height * ((float)targetSize / (float)oldSize.Width));
}
return newSize;
}
}
Here we keep some separation between our database connection and the clients. This is the DataAccess.cs class:

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;

public class DataAccess


{
public DataAccess()
{
}

public static byte[] GetImageByID(int ImageID)


{
//string cnn = "Server=CQSFP260457\\MSSQL2008;Database=master;Trusted_Connection=True;";
string cnn = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;

using (SqlConnection connection = new SqlConnection(cnn))


{
using (SqlCommand command = new SqlCommand("dbo.up_GetImageByID",
connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@ID", ImageID));
connection.Open();

object result = command.ExecuteScalar();

try
{
return (byte[])result;
}
catch
{
return null;
}
}
}
}

public static void InsertImage(string description, byte[] imageAsBytes)


{
//string cnn =
"Server=CQSFP260457\\MSSQL2008;Database=master;Trusted_Connection=True;";
string cnn = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;

using (SqlConnection connection = new SqlConnection(cnn))


{
using (SqlCommand command = new SqlCommand("dbo.up_InsertImage",
connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@description",
description));
command.Parameters.Add(new SqlParameter("@imageAsBytes",
imageAsBytes));
connection.Open();
command.ExecuteNonQuery();
}
}
}

public static List<ImageData> ListImages()


{
//string cnn = "Server=CQSFP260457\\MSSQL2008;Database=master;Trusted_Connection=True;";
string cnn = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;

using (SqlConnection connection = new SqlConnection(cnn))


{
using (SqlCommand command = new SqlCommand("dbo.up_ListImages",
connection))
{
command.CommandType = CommandType.StoredProcedure;
connection.Open();

List<ImageData> list = new List<ImageData>();

using (SqlDataReader reader = command.ExecuteReader())


{
while (reader.Read())
{
ImageData item = new ImageData()
{
ID = (int)reader["ID"],
Description = (string)reader["Description"]
};

list.Add(item);
}
}
return list;
}
}
}

public class ImageData


{
public int ID { get; set; }
public string Description { get; set; }

public ImageData() { }
}
}
Web. Config:

<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.extensions"
type="System.Web.Configuration.SystemWebExtensionsSectionGroup,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting"
type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler"
type="System.Web.Configuration.ScriptingScriptResourceHandlerSection,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35" requirePermission="false"
allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices"
type="System.Web.Configuration.ScriptingWebServicesSectionGroup,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization"
type="System.Web.Configuration.ScriptingJsonSerializationSection,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35" requirePermission="false"
allowDefinition="Everywhere"/>
<section name="profileService"
type="System.Web.Configuration.ScriptingProfileServiceSection,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35" requirePermission="false"
allowDefinition="MachineToApplication"/>
<section name="authenticationService"
type="System.Web.Configuration.ScriptingAuthenticationServiceSection,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35" requirePermission="false"
allowDefinition="MachineToApplication"/>
<section name="roleService"
type="System.Web.Configuration.ScriptingRoleServiceSection,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35" requirePermission="false"
allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings/>

<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data
Source=.\SQLExpress;Integrated Security=True;User
Instance=True;AttachDBFilename=|DataDirectory|imagestore.mdf"/>
</connectionStrings>

<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.DataSetExtensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.

<customErrors mode="RemoteOnly"
defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI"
assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp"
namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd"
type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule"
type="System.Web.Handlers.ScriptModule, System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
<!--
The system.webServer section is required for running ASP.NET AJAX
under Internet
Information Services 7.0. It is not necessary for previous version
of IIS.
-->
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ScriptModule"/>
<add name="ScriptModule" preCondition="managedHandler"
type="System.Web.Handlers.ScriptModule, System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory"/>
<remove name="ScriptHandlerFactoryAppServices"/>
<remove name="ScriptResource"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx"
preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*"
path="*_AppService.axd" preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode"
verb="GET,HEAD" path="ScriptResource.axd"
type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions"
publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0"
newVersion="3.5.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions.Design"
publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0"
newVersion="3.5.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
BinaryViewer.aspx (Nothing but a default aspx page)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BinaryViewer.aspx.cs"


Inherits="BinaryViewer" %>

<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>
BinaryViewer.aspx.cs
Resolves the image datatype stream:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Data;
using System.Data.SqlClient;

public partial class BinaryViewer : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["imageid"] != null &&
Request.QueryString["contenttype"] != null)
{
int id = System.Convert.ToInt32(Request.QueryString["imageid"]);
byte[] byteArray = DataAccess.GetImageByID(id);
//Disply content type of PDF:
//Response.ContentType = "application/pdf";
Response.ContentType =
Request.QueryString["contenttype"].ToString();
Response.BinaryWrite((byte[])byteArray);
}
}
}
SQL Script.sql:

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id =


OBJECT_ID(N'[dbo].[Images]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[Images]
GO
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id =
OBJECT_ID(N'[dbo].[up_GetImageByID]') AND OBJECTPROPERTY(id,N'IsProcedure') =
1)
DROP PROCEDURE [dbo].[up_GetImageByID]
GO
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id =
OBJECT_ID(N'[dbo].[up_InsertImage]') AND OBJECTPROPERTY(id,N'IsProcedure') =
1)
DROP PROCEDURE [dbo].[up_InsertImage]
GO
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id =
OBJECT_ID(N'[dbo].[up_ListImages]') AND OBJECTPROPERTY(id,N'IsProcedure') =
1)
DROP PROCEDURE [dbo].[up_ListImages]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Images](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Description] [nvarchar](50) NOT NULL,
[Image] [image] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[up_GetImageByID]
@ID int
AS

SET NOCOUNT ON

SELECT [Image] FROM Images WHERE ID = @ID


GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[up_InsertImage]
@description nvarchar(50),
@imageAsBytes image
AS

INSERT INTO Images (Description, [Image])


VALUES (@description, @imageAsBytes)
SELECT SCOPE_IDENTITY()
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[up_ListImages]

AS

SELECT ID, Description FROM Images

Potrebbero piacerti anche