0

ファイルは対応するパスにアップロードされていますが、テーブル (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();
 }
4

1 に答える 1

1

フォルダー str に保存されているすべてのファイルを取得できます。配列を使用して保存することもできます。文字列 jst を使用して、フォルダーからすべてのファイルを取得する方法を示しました。

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

getfiles をデータベースに保存できるようになりました。

于 2013-03-24T11:22:20.850 に答える