图片上传 可是出了点问题!
HttpPostedFile UpFile = FileUpload1.PostedFile; //获取对由客户端指定的上传文件的访问FileLength = UpFile.ContentLength;//获取上传文件的字节大小
string hname = FileUpload1.FileName.Substring(FileUpload1.FileName.LastIndexOf(".") + 1).ToString(); ;//截取后缀名?
if (hname == "JPG" || hname == "GIF" || hname == "BMP")
{
if (FileLength > 204800)
Response.Write("<script>alert('对不起,图片大小不能大于200K');window.location.href='admin_link.aspx'</script>");
return;
}
else
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../web.mdb");
conn.Open();
string ImageName = DateTime.Now.ToString("yyyyMMddhhmmssfff") + "." + hname;//图片名称设置为保存的时间
Byte[] FileByte = new Byte[FileLength]; //图象文件储存到数组
Stream ObjectStream = UpFile.InputStream;//建立数据流对像,获取一个 Stream 对象,该对象指向一个上载文件,以准备读取该文件的内容。
ObjectStream.Read(FileByte, 0, FileLength); //读取图象文件数据
string StrSql = "Insert Into link(name,link,image) Values('" + linkname.Text + "','" + linkurl.Text + "',@ImageName)";
OleDbCommand Cmd = new OleDbCommand(StrSql, conn);
//Cmd.Parameters.Add("@Image",OleDbType.Binary, FileLength).Value = FileByte;
Cmd.Parameters.Add("@ImageName", OleDbType.VarChar, 100).Value = ImageName;
//conn.Open();
this.FileUpload1.PostedFile.SaveAs(Server.MapPath("../upload") + "\\" + ImageName);
Cmd.ExecuteNonQuery(); conn.Close();
Response.Write("<script>alert('数据添加成功');window.location.href='admin_link.aspx'</script>");
在调试的时候Cmd.ExecuteNonQuery();出现错误显示说insert语法错误
大家看看到底是怎么回事啊?