导航:首页 > 电脑文件 > 电脑内部文件能存到数据库吗

电脑内部文件能存到数据库吗

发布时间:2023-03-03 01:07:31

如何把文件存放到数据库中

发给你一个上传图片并把它存入数据库的例子。
1.前台<table cellpadding="0" cellspacing="0"
<tr<td colspan="2"</td</tr<tr<td<asp:Label ID="Label1" runat="server" Font-Size="9pt" Text="选择文件"</asp:Label</td
<td align="left"<asp:FileUpload ID="FileUpload1" runat="server" Font-Size="9pt" /</td</tr<tr<td</td
<td align="left"
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="保存"/</td</tr<tr<td</td
<td align="left"
<asp:Label ID="Label3" runat="server" Font-Size="9pt" Width="216px"</asp:Label</td</tr</table
2.后台using System.IO;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page{protected void Button1_Click(object sender, EventArgs e){try{if (this.FileUpload1.PostedFile.FileName != ""){string ImgPath = FileUpload1.PostedFile.FileName;
string ImgName = ImgPath.Substring(ImgPath.LastIndexOf("\\") + 1);
string ImgExtend = ImgPath.Substring(ImgPath.LastIndexOf(".") + 1);
int FileLen = this.FileUpload1.PostedFile.ContentLength;
Byte[] FileData = new Byte[FileLen];
HttpPostedFile hp = FileUpload1.PostedFile;
Stream sr = hp.InputStream;
sr.Read(FileData, 0, FileLen);
SqlConnection con = new SqlConnection("server=(local);user id=sa;pwd=;database=db_07");
con.Open();
SqlCommand com = new SqlCommand("INSERT INTO tb_08 (name) VALUES (@imgdata)", con);
com.Parameters.Add("@imgdata", SqlDbType.Image);
com.Parameters["@imgdata"].Value = FileData;
Label3.Text = "保存成功!";}else{Label3.Text = "请选择文件!";}}catch (Exception error){Label3.Text = "处理失败!原因为:" + error.ToString();}}}

阅读全文

与电脑内部文件能存到数据库吗相关的资料

热点内容
怎么安装电脑版的哈利波特 浏览:65
抖音直播在哪里设置电脑 浏览:977
wifi怎么安装不用电脑 浏览:736
监控电脑显示器黑屏怎么办 浏览:203
电脑炫彩风扇一个多少钱 浏览:793
电脑wifi未连接 浏览:773
电脑蓝屏一小块重启就黑屏 浏览:813
电脑硬盘扫描丢失 浏览:454
t60笔记本电脑 浏览:313
win10电脑开机欢迎转很久 浏览:295
电脑开机嘀嘀嘀响4声 浏览:390
电脑打开无线网怎么显示不出来 浏览:699
win10电脑管家下载 浏览:350
2000左右的平板电脑哪款好 浏览:100
电脑一开机白屏 浏览:485
蓝牙鼠标怎么连接台式电脑 浏览:405
电脑上新安装系统没声音 浏览:697
有在网上免费教英语的网站吗 浏览:114
免费的中学教育资源网站 浏览:678
老机器安装win7时电脑红屏 浏览:169