C#、ASP.NET图片上传问题
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSys...
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.IO;public partial class admin_newsadd : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void LinkButton1_Click1(object sender, EventArgs e) { Response.Write("<script>alert('添加成功');location='newsadd.aspx'</script>"); } protected void Button1_Click(object sender, EventArgs e) { FileUpload FileUpload1 = (FileUpload)DetailsView1.FindControl("FileUpload1"); if (FileUpload1.HasFile) { string _targPath = MapPath("../Upload/") + FileUpload1.FileName + DateTime.Now.ToOADate().ToString() + Path.GetExtension(FileUpload1.FileName); FileUpload1.SaveAs(_targPath); } } protected void Unnamed1_Click(object sender, EventArgs e) { Response.Write("<script>alert('新闻添加成功!')</script>"); }}
待解决的问题:
上传的图片保存到Upload文件夹,路径写入Access数据库中的News表 Upload字段。
截图如下:
图1
图2
图3 展开
待解决的问题:
上传的图片保存到Upload文件夹,路径写入Access数据库中的News表 Upload字段。
截图如下:
图1
图2
图3 展开
展开全部
保存入本地你已经写完了,剩下的就是路径保存入access数据库?
更多追问追答
追问
是的,把图片的路径保存到Access字段。
追答
using System.Data;
using System.Data.OleDb;
string conn="Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=F:\\web\\notesbook\\class\\leavenotes.mdb";
using(OleDbConnection conn= new OleDbConnection(conn))
{
conn.Open();
string strCom = "插入sql语句";
OleDbCommand command =new OleDbCommand(strCom,conn);
command.ExecuteNonQuery();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询