内容更新
我有一个页面要实现更新功能:“
只要当dm.Text 不为空时就可执行内容的更新,同时当FileUpload2不为时,通过上传文件格式判断后也可执行更新”,但是测试的时候发现,当dm.Text 为空时,也可以更新内容,而且如果FileUpload2为空,虽然相应内容会更新但Label2会显示上传文件类型错误,只有FileUpload2不为空时,才会显示修改成功
我的源代码如下:
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
if (dm.Text == null)
{ Label2.Text = "动漫名称不能为空!";
return;
}
else
{
string sqlstr = "update tb_vn set vname='" + dm.Text.Trim() + "',vsc='" + lx.Text.Trim() + "',vmd='" + yy.Text.Trim() + "',vder='" + yy.Text.Trim() + "',vcon='" + gj.Text.Trim() + "', vyear='" + sy.Text.Trim() + "' ,vjj='" + jj.Text.Trim() + "'where vname='" + Request["vname"].ToString() + "'";
sqloperate.DataCom(sqlstr);
if (FileUpload2.FileName !=null)
{
string strExtn = System.IO.Path.GetExtension(FileUpload2.FileName).ToLower();
List<string> lsittype=new List<string>(){".bmp",".jpg",".gif",".bmp","png","jpeg"}; //*.avi *.rmvb *.rm *.asf
if (!lsittype.Contains(strExtn))
{
Label2.Text = "上传文件类型错误";
return; }
else
{
string tupian = "~/Admin/ShiPinImages/" + this.FileUpload2.FileName;
string Path;
string sqlstr1 = "update tb_vn set vtp='" + tupian + "'where vname='" + Request["vname"].ToString() + "'";
sqloperate.DataCom(sqlstr1);
Path = Server.MapPath("~/") + "Admin/ShiPinImages" + "\\" + this.FileUpload2.FileName;
FileUpload2.PostedFile.SaveAs(Path);
}
}
Label2.Text = "修改成功|";