SQL Server企业管理器如何加入图片?
有两种方法,
一种是只存图片所放在服务器的路径,只要存放varchar格式就可以了。
这种方法比较好。不占用数据库太大,但是服务器需要解析路径。
一种是存放二进制的数据Image类型。 sqlserver提供了。在程序中要用流文件的形式,以下是我在网上找到的资料,希望对你有帮助:
保存images进SQL Server数据库
为了保存图片到table你首先得从客户端上传它们到你的web服务器。 你可以创建一个web form,用TextBox得到图片的标题,用HTML File Server Control得到图片文件。确信你设定了Form的encType属性为multipart/fo...全部
有两种方法,
一种是只存图片所放在服务器的路径,只要存放varchar格式就可以了。
这种方法比较好。不占用数据库太大,但是服务器需要解析路径。
一种是存放二进制的数据Image类型。
sqlserver提供了。在程序中要用流文件的形式,以下是我在网上找到的资料,希望对你有帮助:
保存images进SQL Server数据库
为了保存图片到table你首先得从客户端上传它们到你的web服务器。
你可以创建一个web form,用TextBox得到图片的标题,用HTML File Server Control得到图片文件。确信你设定了Form的encType属性为multipart/form-data。
Stream imgdatastream = File1。PostedFile。InputStream;
int imgdatalen = File1。PostedFile。ContentLength;
string imgtype = File1。
PostedFile。ContentType;
string imgtitle = TextBox1。Text;
byte[] imgdata = new byte[imgdatalen];
int n = imgdatastream。
Read(imgdata,0,imgdatalen);
string connstr=
((NameValueCollection)Context。GetConfig
("appSettings"))["connstr"];
SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand
("INSERT INTO ImageStore(imgtitle,imgtype,imgdata)
VALUES ( @imgtitle, @ )", connection );
SqlParameter paramTitle = new SqlParameter
("@imgtitle", SqlDbType。
VarChar,50 );
paramTitle。Value = imgtitle;
command。Parameters。Add( paramTitle);
SqlParameter paramData = new SqlParameter
( "@imgdata", SqlDbType。
Image );
paramData。Value = imgdata;
command。Parameters。Add( paramData );
SqlParameter paramType = new SqlParameter
( "@imgtype", SqlDbType。
VarChar,50 );
paramType。Value = imgtype;
command。Parameters。Add( paramType );
connection。
Open();
int numRowsAffected = command。ExecuteNonQuery();
connection。Close();
。收起