ASP.NET+C# FILEUPLOAD控件,如何上传图片到服务器并保存图片路径到数据库?

ASP.NET+C# FILEUPLOAD控件,如何上传图片到服务器并保存图片路径到数据库?,第1张

我做了个例子给你\x0d\x0a前台:\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a后台:\x0d\x0a protected void Button1_Click(object sender, EventArgs e)\x0d\x0a{\x0d\x0aFileUpload1.SaveAs(Server.MapPath("img/"+FileUpload1.FileName))//上传图片\x0d\x0aImage1.ImageUrl = "~/img/" + FileUpload1.FileName//图片路径(将这个数据保存到数据库就可以了。img为项目里一个文件夹的名称)\x0d\x0a} 回答于 2022-11-17

'================================================================

'过程作用:打开数据库连接

'================================================================

Dim Conn,Auto_DataBaseName,Auto_HostName,Auto_DataBaseUrl

Sub ConnOpen()

If Auto_DataBaseKind = "0" Then

Auto_DataBaseName = "DataBaseName" '数据库名称

Auto_HostName = "localhost" '服务器名称或IP

Auto_UserId = "sa" '登陆数据库用户ID

Auto_LogoPassWord = "" '登陆数据库密码

Auto_OaClassConnStr = "Provider = SqloledbUser ID = " &Auto_UserId &"Password = " &Auto_LogoPassWord &"Initial Catalog = " &Auto_DataBaseName &"Data Source = " &Auto_HostName &""

ElseIf Auto_DataBaseKind = "1" Then

Auto_DataBaseName = "Data.mdb" '数据库名称

Auto_DataForder = "" 'Access数据库存放目录,请务必以“\”结尾

Auto_DataBaseUrl = Server.MapPath(Auto_DataForder &Auto_DataBaseName)

Auto_OaClassConnStr = "Provider = Microsoft.Jet.OLEDB.4.0Data Source = " &Auto_DataBaseUrl

Else

Response.Write("数据库类型定义错误,请检查文件DbConn.asp中数据库类型定义是否正确!")

Response.End()

End If

On Error Resume Next

Set Conn = Server.CreateObject("ADODB.Connection")

Conn.open Auto_OaClassConnStr

If Err Then

err.Clear

Set Conn = Nothing

Response.Write ("数据库连接出错,请检查文件Conn.asp中连接字符串。")

Response.End()

End If

End Sub

'================================================================

'过程作用:关闭数据库连接

'================================================================

Sub ConnClose()

Conn.close()

Set Conn = Nothing

End Sub

%>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9928906.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存