[HttpPost]
public ActionResult Create(Showroom showroom)
{
objShowroom.InsertShowroomDetails(showroom);
return RedirectToAction("Index");
}
如果我编辑任何文本框图像将在回发或往返中消失
模型文件夹:
public int UpdateShowroomDetails(Showroom objShowroom)
{
sqlCommandText = "Update Showroom Set CARIMAGE='" + objShowroom.CARIMAGE + "', CARNAME='" + objShowroom.CARNAME + "', CARBRAND='" + objShowroom.CARBRAND + "', PRICE=" + objShowroom.PRICE + " Where ID="+objShowroom.ID ;
return objDAL.ExecuteNonQuery(sqlCommandText);
}
答案 0 :(得分:0)
以下是我使用ado.net将图像保存到数据库的方法。希望这会对你有所帮助
string fileName = string.Empty;
string servr_path = string.Empty;
string serviceId = string.Empty;
string planId = string.Empty;
if (IdProofFile.HasFile && IdProofFile.PostedFile.FileName != "")
{
string fileType = IdProofFile.PostedFile.ContentType;
if (fileType == "image/jpg" || fileType == "image/jpeg" || fileType == "image/png" || fileType == "image/gif")
{
int fileSize = IdProofFile.PostedFile.ContentLength;
if (fileSize <= 2097152)
{
//fileName = System.IO.Path.GetFileName(IdProofFile.PostedFile.FileName);
fileName = "ID-" + txt_FirstName.Text + "_" + txt_LstName.Text + DateTime.Now.ToString("ddmmyy_hhMMss") + Path.GetExtension(IdProofFile.PostedFile.FileName);
string serverFolder = Server.MapPath("idProof//");
if (!System.IO.Directory.Exists(serverFolder))
{
System.IO.Directory.CreateDirectory(serverFolder);
}
servr_path = serverFolder + fileName;
foreach (int i in ddlservices.GetSelectedIndices())
{
serviceId += "," + ddlservices.Items[i].Value;
}
IdProofFile.SaveAs(servr_path);
}
}
else
{
}
}
else
{
}
}
else
{
//ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "mask();", true);
mpepopup.Show();
lblMsg.Text = "Min File Size Must Be Greater Than 5 KB and Less Than 2 MB";
}
}
else
{
mpepopup.Show();
// ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "mask();", true);
lblMsg.Visible = true;
lblMsg.Text = "Please upload an image of *.jpg/*.jpeg/*.png/*.gif/*.bmp file type only!!!";
}
}
else
{
mpepopup.Show();
lblMsg.Text = "ID Proof File Not Selected.";
}