如何在ASP.NET中将图像添加到数据库? [英] How can l add image to database in ASP.NET ?

查看:94
本文介绍了如何在ASP.NET中将图像添加到数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过网站将图片添加到我的数据库中,我已经为它编写了代码,但由于某些原因它无法正常工作!!



如果单击按钮,则会出现此错误: -



_ System.Web.dll中出现System.Web.HttpException类型的异常,但是不在用户代码中处理。



_附加信息:SaveAs方法配置为需要根路径,路径'Images / Image0 2'不是root。



错误引用此代码: -

 imageFile.SaveAs(Images /& N_image)





我尝试过:



  Dim  ftype  As   String  
Dim N_image As String

ftype = System.IO.Path.GetExtension(imageFi le.FileName)

ImgDS.InsertParameters( Hall_Namber)。DefaultValue = DropDownList1.SelectedValue
ImgDS.InsertParameters( Image)。DefaultValue = N_image
ImgDS.Insert()

N_image = 图像& DropDownList1.SelectedValue& & GridView3.Rows.Count + 1
imageFile.SaveAs( Images /& N_image)

解决方案

请先阅读我的评论。 ..



Google上有很多例子(使用声明: asp.net vb.net将图像插入数据库),见:

如何使用C#和VB.Net在ASP.Net中的数据库中保存(插入)图像 [ ^ ]

保存和检索来自使用VB.NET的SQL Server数据库的图像 [ ^ ]

使用ASP.NET 2.0和ASP.NET 3.5从数据库保存和检索图像DotNetCurry [ ^ ]

如何使用ASP.Net上传和保存图像到数据库 [ ^ ]



祝你好运!

I want to add a picture to my database through the website, I've written the code for it, but it does not work for some reason!!

This error appears to me if I click on button :-

_ an exception of type "System.Web.HttpException' occurred in System.Web.dll but was not handled in user code.

_ Additional information: The SaveAs method is configured to require a rooted path, and the path'Images/Image0 2' is not rooted.

The error refers to this code:-

imageFile.SaveAs("Images/" & N_image)



What I have tried:

Dim ftype As String
Dim N_image As String

ftype = System.IO.Path.GetExtension(imageFile.FileName)

ImgDS.InsertParameters("Hall_Namber").DefaultValue = DropDownList1.SelectedValue
ImgDS.InsertParameters("Image").DefaultValue = N_image
ImgDS.Insert()

N_image = "Image" & DropDownList1.SelectedValue & " " & GridView3.Rows.Count + 1
imageFile.SaveAs("Images/" & N_image)

解决方案

Please, read my comment first...

There's lot of examples on Google (using statement: asp.net vb.net insert image into database ), see:
How to save ( insert ) Image in Database in ASP.Net using C# and VB.Net[^]
Save and Retrieve Image from a SQL Server Database using VB.NET[^]
Save and Retrieve Images from the Database using ASP.NET 2.0 and ASP.NET 3.5 | DotNetCurry[^]
How to Upload and Save Images Into Database Using ASP.Net[^]

Good luck!


这篇关于如何在ASP.NET中将图像添加到数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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