if (this.FileUpload1.HasFile)
{
string filename = this.FileUpload1.FileName;
string type = filename.Substring(filename.LastIndexOf(".") + 1).ToLower();
if (type.Equals("jpg") && type.Equals("gif") && type.Equals("bmp"))
{
string dt = DateTime.Now.ToString("yyMMddhhmmss");
string savename = dt + "." + type;
string path = "~/BookImages/" + savename;
TextBox1.Text = path;
this.FileUpload1.SaveAs(Server.MapPath("Images") + "\\" + savename); }
try
{
string selstr = "update Book set PictureUrl='" + TextBox1.Text + "'";
Database db1 = new Database();
db.ExecuteSQL(selstr);
this.FileUpload1.SaveAs(Server.MapPath("image") + "\\" + savename);
Response.Write("<Script Language=JavaScript>alert(\"成功!\")</Script>");
}
catch
{
Response.Write("<Script Language=JavaScript>alert(\"失败!\")</Script>"); }
}
else
{
Response.Write("<Script Language=JavaScript>alert(\"文件类型不正确!\")</Script>");
}
string instring = "insert into [Book](BookName,CategoryID,Price,DisPrice,Publiser,PublishDate,Author,PageNum,PictureUrl,Description) values(" + "'" + txtbookName.Text + "','" + DropDownLisCategory.SelectedItem.Value + "','" + txtPrice + "','" + txtDisPrice + "','" + txtPublisher + "','" + DateTime.Now.ToString() + "','" + txtAuthor + "','" + txtPageNum + "','" + FileUpload1.FileName.ToString() + "','" + txtPro + "')";
Database db = new Database(); db.ExecuteSQL(instring);
{
string filename = this.FileUpload1.FileName;
string type = filename.Substring(filename.LastIndexOf(".") + 1).ToLower();
if (type.Equals("jpg") && type.Equals("gif") && type.Equals("bmp"))
{
string dt = DateTime.Now.ToString("yyMMddhhmmss");
string savename = dt + "." + type;
string path = "~/BookImages/" + savename;
TextBox1.Text = path;
this.FileUpload1.SaveAs(Server.MapPath("Images") + "\\" + savename); }
try
{
string selstr = "update Book set PictureUrl='" + TextBox1.Text + "'";
Database db1 = new Database();
db.ExecuteSQL(selstr);
this.FileUpload1.SaveAs(Server.MapPath("image") + "\\" + savename);
Response.Write("<Script Language=JavaScript>alert(\"成功!\")</Script>");
}
catch
{
Response.Write("<Script Language=JavaScript>alert(\"失败!\")</Script>"); }
}
else
{
Response.Write("<Script Language=JavaScript>alert(\"文件类型不正确!\")</Script>");
}
string instring = "insert into [Book](BookName,CategoryID,Price,DisPrice,Publiser,PublishDate,Author,PageNum,PictureUrl,Description) values(" + "'" + txtbookName.Text + "','" + DropDownLisCategory.SelectedItem.Value + "','" + txtPrice + "','" + txtDisPrice + "','" + txtPublisher + "','" + DateTime.Now.ToString() + "','" + txtAuthor + "','" + txtPageNum + "','" + FileUpload1.FileName.ToString() + "','" + txtPro + "')";
Database db = new Database(); db.ExecuteSQL(instring);
还有就是你在
string instring = "insert into [Book](BookName,CategoryID,Price,DisPrice..这里设置一个断点调试一下看看instring的值是什么,在查询分析器中看看有没有语法错误,能不能执行等。
{
if (this.FileUpload1.HasFile)
{
string filename = this.FileUpload1.FileName;
string type = filename.Substring(filename.LastIndexOf(".") + 1).ToLower();
if (type.Equals("jpg") && type.Equals("gif") && type.Equals("bmp"))
{
string dt = DateTime.Now.ToString("yyMMddhhmmss");
string savename = dt + "." + type;
string path = "~/BookImages/" + savename;
TextBox1.Text = path;
this.FileUpload1.SaveAs(Server.MapPath("Images") + "\\" + savename); }
try
{
string selstr = "update Book set PictureUrl='" + TextBox1.Text + "'";
Database db1 = new Database();
db.ExecuteSQL(selstr);
this.FileUpload1.SaveAs(Server.MapPath("image") + "\\" + savename);
Response.Write(" <Script Language=JavaScript>alert(\"成功!\") </Script>");
}
catch
{
Response.Write(" <Script Language=JavaScript>alert(\"失败!\") </Script>"); }
}
else
{
Response.Write(" <Script Language=JavaScript>alert(\"文件类型不正确!\") </Script>");
}
string instring = "insert into [Book](BookName,CategoryID,Price,DisPrice,Publiser,PublishDate,Author,PageNum,PictureUrl,Description) values(" + "'" + txtbookName.Text + "','" + DropDownLisCategory.SelectedItem.Value + "','" + txtPrice + "','" + txtDisPrice + "','" + txtPublisher + "','" + DateTime.Now.ToString() + "','" + txtAuthor + "','" + txtPageNum + "','" + FileUpload1.FileName.ToString() + "','" + txtPro + "')";
Database db = new Database(); db.ExecuteSQL(instring);
}
catch(Exception ex)
{
MessageBox.Show(ex.message);
}