0
這是我的代碼,這一切工作正常,所以我不想改變我這樣做的方式。然而,我不知道該如何處理圖像。如何顯示它供用戶編輯,然後將其新上載更新到數據庫?如何更新數據庫中的圖像? c#asp.net sql
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
int row = 0;
if (Request.QueryString["Advertisement"] != null) {
row = int.Parse(Request.QueryString["Advertisement"]);
}
else
{
Response.Redirect("ViewAdvertisements.aspx");
}
string connectionString = WebConfigurationManager.ConnectionStrings["ElmtreeConnection"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connectionString);
myConnection.Open();
string query = "SELECT * FROM Products WHERE [email protected]";
SqlCommand myCommand = new SqlCommand(query, myConnection);
myCommand.Parameters.AddWithValue("@rowid", row);
SqlDataReader rdr = myCommand.ExecuteReader();
while (rdr.Read())
{
editadtitle.Text = (rdr["name"].ToString());
editdescription.Text = (rdr["description"].ToString());
editprice.Text = (rdr["price"].ToString());
editcategory.Text = (rdr["categoryid"].ToString());
}
}
}
protected void btnSignOut_Click(object sender, EventArgs e)
{
Session["SELLER"] = null;
Response.Redirect("Default.aspx");
}
protected void updatebutton_Click(object sender, EventArgs e)
{
string connectionString = WebConfigurationManager.ConnectionStrings["ElmtreeConnection"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connectionString);
myConnection.Open();
string adtitleupdate = editadtitle.Text;
int row = int.Parse(Request.QueryString["Advertisement"]);
string descriptionupdate = editdescription.Text;
string priceupdate = editprice.Text;
string categoryupdate = editcategory.Text;
string query = "UPDATE Products SET Name = @newadtitle, Description = @newdescription, Price = @newprice, CategoryId = @newcategory WHERE Id = @id";
SqlCommand myCommand = new SqlCommand(query, myConnection);
myCommand.Parameters.AddWithValue("@newadtitle", adtitleupdate);
myCommand.Parameters.AddWithValue("@id",row);
myCommand.Parameters.AddWithValue("@newdescription", descriptionupdate);
myCommand.Parameters.AddWithValue("@newprice", priceupdate);
myCommand.Parameters.AddWithValue("@newcategory", categoryupdate);
updatelabel.Text = "Your information has now been updated. ";
myCommand.ExecuteNonQuery();
myConnection.Close();
}
}
您應該添加一個img標籤並設置從db中檢索到的src和一個標籤以便選擇一個新標籤。 – Mehrdad
什麼形象?在你提供的代碼中,我沒有看到任何可以處理圖像的代碼。 – Patrick