跪求C#大神。将图片上传到网页,然后存入数据库中。(类似于淘宝买家秀的上传图片)
代码如下:(出现错误)protectedvoidButton2_Click(objectsender,EventArgse){intstate;stringpicpath...
代码如下:(出现错误)
protected void Button2_Click(object sender, EventArgs e)
{
int state;
string picpath;
//string useridnumber = Session["UserId"].ToString();
string CheckFlag;
string Pic;
SqlConnection conn = new SqlConnection(secondhand.SqlBase);
conn.Open();
HttpPostedFile httpup = FileUpload1.PostedFile;
if (httpup.ContentLength != 0)
{
string PathFileName = httpup.FileName;
int i = PathFileName.LastIndexOf("\\");
string filename = PathFileName.Substring(i + 1);
httpup.SaveAs(Server.MapPath("images/pic/" + filename));
picpath = "images/pic/" + filename;
Pic = "1";
CheckFlag = "1";
}
else
{
picpath = null;
Pic = "0";
CheckFlag = "0";
}
string test = "insert into shangpin(shangpin_title,shangpin_type,shangpin_newORold,shangpin_price,shangpin_bargain,shangpin_introduction,shangpin_image)"
+ "values('" + TextBox1.Text + " ','" + DropDownList1.SelectedIndex.ToString() + "' ,'" + DropDownList2.SelectedIndex.ToString() + " ','" + TextBox2.Text + "',' " + DropDownList3.SelectedIndex.ToString() + "','" + TextBox3.Text + "' ,'" + FileUpload1.ToString() + "')";
state = secondhand.AddInfo(test, conn);
} 展开
protected void Button2_Click(object sender, EventArgs e)
{
int state;
string picpath;
//string useridnumber = Session["UserId"].ToString();
string CheckFlag;
string Pic;
SqlConnection conn = new SqlConnection(secondhand.SqlBase);
conn.Open();
HttpPostedFile httpup = FileUpload1.PostedFile;
if (httpup.ContentLength != 0)
{
string PathFileName = httpup.FileName;
int i = PathFileName.LastIndexOf("\\");
string filename = PathFileName.Substring(i + 1);
httpup.SaveAs(Server.MapPath("images/pic/" + filename));
picpath = "images/pic/" + filename;
Pic = "1";
CheckFlag = "1";
}
else
{
picpath = null;
Pic = "0";
CheckFlag = "0";
}
string test = "insert into shangpin(shangpin_title,shangpin_type,shangpin_newORold,shangpin_price,shangpin_bargain,shangpin_introduction,shangpin_image)"
+ "values('" + TextBox1.Text + " ','" + DropDownList1.SelectedIndex.ToString() + "' ,'" + DropDownList2.SelectedIndex.ToString() + " ','" + TextBox2.Text + "',' " + DropDownList3.SelectedIndex.ToString() + "','" + TextBox3.Text + "' ,'" + FileUpload1.ToString() + "')";
state = secondhand.AddInfo(test, conn);
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询