0
我需要幫助,我將文件目錄插入數據庫,但它不考慮數據庫中的txtStoryTitle.Text,例如,如果我在txtStoryTitle中鍵入HelloWorld。它在數據庫中顯示爲Images/Story //(文件名),而不是圖像/ Story/HelloWorld /(文件名)。我正在使用MySQL(工作臺)。c#如何插入數據庫
請提前給我一個建議/解決方案,謝謝!
下面是部分代碼:
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
EnsureDirectoriesExist();
String filepathImage = (@"Images/Story/" + txtStoryTitle.Text + "/" + e.FileName);
AjaxFileUpload1.SaveAs(Server.MapPath(filepathImage));
Session["filepathImage"] = filepathImage;
}
public void EnsureDirectoriesExist()
{
if (!System.IO.Directory.Exists(Server.MapPath(@"Images/Story/" + txtStoryTitle.Text + "/")))
{
System.IO.Directory.CreateDirectory(Server.MapPath(@"Images/Story/" + txtStoryTitle.Text + "/"));
}
}
protected void btnDone_Click(object sender, EventArgs e)
{
if (Session["filepathImage"] != null)
{
string filepathImage = Session["filepathImage"] as string;
act.ActivityName = dropListActivity.SelectedItem.Text;
act.Title = txtStoryTitle.Text;
act.FileURL = filepathImage;
daoStory.Insert(act);
daoStory.Save();
}
您可以顯示視圖的外觀 - 特別是名爲'txtStoryTitle'的控件' – aquaraga
什麼是'daoStory'並顯示'daoStory.Insert'方法的代碼? – Damith
檢查您是否從txtStoryTitle.Text獲取任何內容!正如我看到它,你會得到空字符串,這就是爲什麼它顯示爲圖像/故事//(文件名) – Sylca