繁体   English   中英

如何在AjaxFileUpload ASP.NET之后更新数据库表

[英]How to Update Database Table after AjaxFileUpload ASP.NET

文件正在上传到相应的路径,但是表(fileinfo)没有更新。.在文件上传到服务器后如何实现表更新

 protected void UploadComplete(Object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
 {
    string str = RadioButton1.Text;
    string path = Server.MapPath("~/" + str +"/") + e.FileName;
    AjaxFileUpload1.SaveAs(path);
    SqlConnection con = new SqlConnection("Data Source=localhost\\sqlexpress; Initial Catalog=example;user ID=sa;password=*******;");
    con.Open();        
    string command1 = "insert into fileinfo(fileid,filename,date1) values(@fileid,@filename,@date1)";
    SqlCommand command = new SqlCommand(command1, con);
    command.Parameters.AddWithValue("@fileid", "101");
    command.Parameters.AddWithValue("@filename", e.FileName);
    command.Parameters.AddWithValue("@date1", DateTime.Now);
    command.ExecuteNonQuery();
 }

您可以检索存储在str文件夹中的所有文件,也可以使用数组进行存储,我已经使用字符串jst向您展示了如何从文件夹中获取所有文件

string getfile="";
foeach(string f in Directory.GetFiles(Server.MapPath("~/"+str+"/"))
{
  getfiles= getfiles + f + ",";
 }

现在,您可以将getfiles存储在数据库中,希望对您有所帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM