简体   繁体   English

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

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

The file is uploading to the corresponding path but table (fileinfo) is not updating.. How to achieve the table updation after a file is being uploaded to the server 文件正在上传到相应的路径,但是表(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();
 }

You can retreive all the files stored in the folder str, you can take array also to store, i have used the string jst to show you, that how you can get all the files from the folder 您可以检索存储在str文件夹中的所有文件,也可以使用数组进行存储,我已经使用字符串jst向您展示了如何从文件夹中获取所有文件

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

Now You can store the getfiles in your database, I hope it will help you out 现在,您可以将getfiles存储在数据库中,希望对您有所帮助

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

相关问题 如何在ASP.NET MVC 5 Razor数据库中更新表 - How to update table in ASP.NET MVC 5 Razor Database 如何在 ASP.NET Core 中更新现有的脚手架数据库的表 - How to update a table of an existing, scaffolded database in ASP.NET Core asp.net:AjaxFileUpload OnUploadComplete事件 - asp.net : AjaxFileUpload OnUploadComplete event 无法更新在Firefox浏览器上使用AjaxFileUpload控件的asp.net WebForm中的标签 - Unable to update label in an asp.net WebForm which uses AjaxFileUpload control on Firefox browser 使用ASP.NET 4.0的ajaxcontroltoolkit查看错误ajaxfileupload数据导入和更新面板 - Seeing the error with ajaxcontroltoolkit ajaxfileupload data import and update panel for ASP.NET 4.0 ASP.NET 5 EF 7无法更新数据库表中的条目 - ASP.NET 5 EF 7 cannot update entry in database table 在C#ASP.NET中更新数据库表单元 - Update a database table cell in c# asp.net 如何使用AjaxFileUpload.js将HTML输入文件传递到C#ASP.Net? - How do you pass HTML input files to C# ASP.Net using AjaxFileUpload.js? 如何使用asp.net获取使用ajaxfileupload上传的图像宽度和高度 - How to get image width and height uploaded using ajaxfileupload asp.net 数据库更改时如何在数据库优先方法ASP.NET“核心”中更新模型(添加了新表) - How to update the model in Database First Approach ASP.NET “Core” when the DB changes (A new table is added)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM