将图像上传到数据库 [英] Upload an image to database

查看:86
本文介绍了将图像上传到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将图像保存到SQL Server数据库。 (在ASP.NET项目中)



图像从文件上传按钮加载。



please any一个人建议一种方法来实现这个目标!



提前致谢!



我有什么试过:



< asp:FileUpload ID =fileuprunat =server/>

string sql =INSERT INTO User_Info(Image)values(@image);

SqlCommand cmd = new SqlCommand(sql,con);



string strname = fileup.FileName.ToString();

cmd.Parameters.AddWithValue(@ image,strname);

I wanted to save an image to SQL server database. (In an ASP.NET project)

Image is loaded from File upload button.

please any one suggest a way to accomplish this!

Thanks in Advance!

What I have tried:

<asp:FileUpload ID="fileup" runat="server" />
string sql = "INSERT INTO User_Info(Image) values(@image)";
SqlCommand cmd = new SqlCommand(sql,con);

string strname = fileup.FileName.ToString();
cmd.Parameters.AddWithValue("@image", strname);

推荐答案

您可以将Image保存到文件夹并将路径保存在db中,也可以将图像字节保存到数据库中。两者都有优点和缺点。如果卡住,可以在线获取大量示例。
You either save the Image to a folder and save the path in the db, or you save the image bytes into the database. Both have advantages and disadvantages. Lots of examples online if you get stuck.


将图像保存在服务器上的文件夹中,并将该图像文件的路径保存在数据库表中。
Save the image in folder on server and save that image file's path in database table.


这篇关于将图像上传到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆