如何从我的计算机中选择一个图像并插入到sql表中. [英] How to select an image from my computer and insert into sql table.
本文介绍了如何从我的计算机中选择一个图像并插入到sql表中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以告诉我如何从计算机中选择图像并将其插入数据库表列中.
解决方案
您好,
< 表格 id =" runat =" < asp:FileUpload id =" runat 服务器" / < asp:Button 运行 =" id UploadButton " 文本 上传" onclick UploadButton_Click" / > < br / < ">> 跨度> < asp:Label 运行 =" id StatusLabel " 文本 上传状态:" / > < /form >
背后的代码
受保护的 无效 UploadButton_Click(对象发件人,EventArgs e) { 如果(FileUploadControl.HasFile) { 尝试 { 如果(FileUploadControl.PostedFile.ContentType == " ) { 如果(FileUploadControl.PostedFile.ContentLength < 102400 跨度>) { 字符串 filename = Path.GetFileName(FileUploadControl.FileName); FileUploadControl.SaveAs(Server.MapPath(" )+文件名); StatusLabel.Text = " ; } 其他 StatusLabel.Text = " ; } 其他 StatusLabel.Text = " ; } 捕获(例外) { StatusLabel.Text = " + ex.Message; } } }
尝试
http://www.4guysfromrolla.com/articles/120606-1.aspx [ ^ ]
使用Streded Procedures和C#.net从SQL Server存储和检索图像 [ ^ ]
http://www. dotnetlogix.com/Article/aspnet/194/Save-and-retrieve-image-to-and-from-database-in-aspnet.html [ 解决方案
Hi,
<form id="form1" runat="server"> <asp:FileUpload id="FileUploadControl" runat="server" /> <asp:Button runat="server" id="UploadButton" text="Upload" onclick="UploadButton_Click" /> <br /><br /> <asp:Label runat="server" id="StatusLabel" text="Upload status: " /> </form>
Code behind
protected void UploadButton_Click(object sender, EventArgs e) { if(FileUploadControl.HasFile) { try { if(FileUploadControl.PostedFile.ContentType == "image/jpeg") { if(FileUploadControl.PostedFile.ContentLength < 102400) { string filename = Path.GetFileName(FileUploadControl.FileName); FileUploadControl.SaveAs(Server.MapPath("~/") + filename); StatusLabel.Text = "Upload status: File uploaded!"; } else StatusLabel.Text = "Upload status: The file has to be less than 100 kb!"; } else StatusLabel.Text = "Upload status: Only JPEG files are accepted!"; } catch(Exception ex) { StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; } } }
Try
http://www.4guysfromrolla.com/articles/120606-1.aspx[^]
Storing and Retrieving Images from SQL Server Using Strored Procedures and C#.net[^]
http://www.dotnetlogix.com/Article/aspnet/194/Save-and-retrieve-image-to-and-from-database-in-aspnet.html[^]
这篇关于如何从我的计算机中选择一个图像并插入到sql表中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文