ASP.NET 在线图书销售系统,上架图书上传“时间”代码出错,望大神指正!!!
public partial class admin_addproduvts : System.Web.UI.Page{
public string FileNamePic;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string filename = "pic" + System.DateTime.Now.ToString("YYYYMMDDHHmmssff");
Boolean FileOK = false;
string path = Server.MapPath("~/picture/");
if (FileUpload1.HasFile)
{
string fileExtension = (FileUpload1.FileName).ToLower();
string[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{ FileOK = true; break; }
}
if (FileOK)
{
try
{
FileUpload1.PostedFile.SaveAs(path + filename + fileExtension);
Session["FileNamePic"] = filename + fileExtension;
Label1.Text = "文件上传成功!";
}
catch (Exception ex)
{ Label1.Text = "文件未上传!"; }
}
}
else { Label1.Text = "文件不是图片类型"; }
}
protected void Button2_Click(object sender, EventArgs e)
{
}
protected void Button3_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ShoppingWebDBConnectionString"].ConnectionString);
conn.Open();
string sql = "insert into Products(Name,Picture)values(@Name,@Picture)";
SqlCommand cmd1=new SqlCommand(sql,conn);
cmd1.Parameters.Add(new SqlParameter("@Name", SqlDbType.VarChar, 100));
cmd1.Parameters["@Name"].Value = this.TextBox1.Text;
cmd1.Parameters.Add(new SqlParameter("@ProductTypeID", SqlDbType.VarChar, 50));
cmd1.Parameters["@ProductTypeID"].Value = this.TextBox2.Text;
cmd1.Parameters.Add(new SqlParameter("@Author", SqlDbType.VarChar, 50));
cmd1.Parameters["@Author"].Value = this.TextBox4.Text;
cmd1.Parameters.Add(new SqlParameter("@PublicTime", SqlDbType.DateTime));
cmd1.Parameters["PublicTime"].Value = System.DateTime.Now;
cmd1.Parameters.Add(new SqlParameter("@InPrice", SqlDbType.Money, 50));
cmd1.Parameters["InPrice"].Value = System.Convert.ToDouble(this.TextBox6.Text);
cmd1.Parameters.Add(new SqlParameter("@OutPrice", SqlDbType.Money, 50));
cmd1.Parameters["OutPrice"].Value = System.Convert.ToDouble(this.TextBox7.Text);
cmd1.Parameters.Add(new SqlParameter("@Picture",SqlDbType.VarChar,50));
cmd1.Parameters["@Picture"].Value=Session["FileNamePic"].ToString();
cmd1.ExecuteNonQuery();
conn.Close();
Page.Controls.Clear();
Response.Write(TextBox1.Text+"添加成功!");
}
}
出现如下错误,望大神指正!