[英]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.