asp.net問題~~急問>

2008-05-21 4:33 am
我係用web-developer做ga
我而家有2個database~~table
其中1個叫photo啦~~另1個叫detail啦
detail入面有個column Name叫做 ""A ID"" 我已經將呢個Fk左去photo入面既 ID
咁點可以係1個aspx到 用formview用photo既ID自動搵到detail入面既data比我進行更改-v-
又或者可以換個方法做~~就係用1個repeater顯示到2個database既table資料

仲有個問題係點解我upload圖片既時候點解佢會話我以下句野error
protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
FormView formView = (FormView)sender;
FileUpload upload = (FileUpload)formView.FindControl("ImageFileUpload");
string physicalPath = Server.MapPath("images/photo");

string fileTitle = Path.GetFileName(upload.FileName);<---------------------

string fileName = Path.Combine(physicalPath, fileTitle);
upload.SaveAs(fileName);
e.NewValues["ImageUrl"] = string.Format("images/photo/{0}", fileTitle);
}

回答 (1)

2008-05-21 12:51 pm
✔ 最佳答案
a number of issues:
1.
string physicalPath = Server.MapPath("images/photo");
should be changed to
string physicalPath = Server.MapPath("images\\photo"); <-- two slashes
because MapPath() is returning the file system path, not internet path

2. the error line
string fileTitle = Path.GetFileName(upload.FileName);
shouldbe changed to
string fileTitle = Path.GetFileName(upload.PostedFile.FileName);

3.
upload.SaveAs(fileName);
should be changed to
upload.PostedFile.SaveAs(fileName);


關於 photo 同 detail,一個 photo 有多個 detail,DataAdapter 個 sql statement 就要按 photo id 而更改,例如

string sql = "select * from detail where aid=" + photoid;
OleDbDataAdapter da = new OleDbDataAdapter(sql, conectionString);
DataTable dt = new DataTable();
da.Fill(dt);
formView.DataSource = dt.DefaultView;
formView.DataBind();


用一個 repeater顯示兩個 database table 既資料
必須用 sql select statemnt 將兩個 table join 起,repeater 個 DataSource 設定為 sql statement。

不知答案是否你想要,有問題再補充。


收錄日期: 2021-04-25 20:32:47
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080520000051KK02552

檢視 Wayback Machine 備份