protected void Page_Load(object sender, EventArgs e)
{
string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(".//App_Data//db1.mdb");
OleDbConnection conn = new OleDbConnection(constr);
OleDbDataAdapter da = new OleDbDataAdapter("select type_id,type_name from type ", conn);
DataSet ds = new DataSet();
da.Fill(ds, "type");
DropDownList1.DataSource = ds.Tables["type"].DefaultView;
//绑定DropDownList1
DropDownList1.DataTextField = "type_name";
DropDownList1.DataValueField = "type_id";
DropDownList1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
//上传文件
string savepath = Server.MapPath("file/");
if (TextBox1.Text == "" || TextBox2.Text == "" || TextBox3.Text == "")
{
Label1.Text = "标题,作者,内容不能为空!";
}
else
if (TextBox1.Text.Length > 50)
Label1.Text = "你输入的标题过长!";
else if (FileUpload1.HasFile)
{
string filename = FileUpload1.FileName;
savepath += filename;
FileUpload1.SaveAs(savepath);
}
//数据库连接
string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(".//App_Data/db1.mdb");
OleDbConnection conn = new OleDbConnection(constr);
string insersqlstr = "insert into content(title,author,content,img, type_id) values('" + TextBox1.Text + "','" + TextBox2.Text + "'," + TextBox3.Text + "','" + FileUpload1.FileName.ToString() + "','" + DropDownList1.SelectedItem.Value + "'";
OleDbCommand cmd = new OleDbCommand(insersqlstr, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
Response.Redirect("Default.aspx");
}
这是添加信息的后台代码,在浏览时,出现图中所出现的错误,不知应该如何解决,望各位指教!!老板在催,请大家一定要帮下!!!