向SQL Server数据库添加图片

来源:互联网 发布:wpscan更新不了数据库 编辑:程序博客网 时间:2024/04/27 23:43
向SQL Server数据库添加图片
作者:孟宪会 出自:【孟宪会之精彩世界】 发布日期:2003年6月20日 7点26分46秒

下面的代码实现向SQL Server数据库添加图片和文字的功能。

首先,在SQL查询分析器中执行下面的语句,以创建表和存储过程。

Drop Table PersonGoCreate Table Person(PersonID Int Identity,PersonEmail Varchar(255),PersonName Varchar(255),PersonSex Char(1),PersonDOB DateTime,PersonImage Image,PersonImageType Varchar(255))Drop Proc sp_person_ispGoCreate Proc sp_person_isp@PersonEmail Varchar(255),@PersonName Varchar(255),@PersonSex Char(1),@PersonDOB DateTime,@PersonImage Image,@PersonImageType Varchar(255)AsBegin Insert into Person (PersonEmail, PersonName, PersonSex, PersonDOB, PersonImage, PersonImageType) Values (@PersonEmail, @PersonName, @PersonSex, @PersonDOB, @PersonImage, @PersonImageType)EndGo

下面就是完整的代码,拷贝即可运行:

<%@ Import Namespace="System.IO" %><%@ Import Namespace="System.Data.SqlClient" %><%@ Import Namespace="System.Data" %><%@ Page Language="vb" %><HTML><HEAD><title>向SQL Server插入图片</title></HEAD><body style="FONT: 9pt 宋体"> <form enctype="multipart/form-data" runat="server" ID="Form1"> </asp:TableCell> </asp:TableRow> </asp:TableCell> </asp:TableCell> </asp:TableRow> </asp:TableCell> </asp:TableCell> </asp:TableRow> </asp:TableCell> </asp:TableCell> </asp:TableRow> </asp:TableCell> </asp:TableCell> </asp:TableRow> </asp:TableCell> <input type="file" id="PersonImage" runat="server" NAME="PersonImage" /></asp:TableCell> </asp:TableRow> </asp:TableCell> </asp:TableRow> </asp:Table> </form></body></HTML>