使用Microsoft Visual Studio 2005怎么实现上传图片
使用MicrosoftVisualStudio2005怎么实现上传图片恩上穿图片后图片保存到某个文件夹中并储存该图片保存后的路径在我的代码中修改protectedvoid...
使用Microsoft Visual Studio 2005怎么实现上传图片
恩 上穿图片后 图片保存到某个文件夹中 并储存该图片保存后的路径
在我的代码中修改
protected void btnAdd_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["aspnetdbConnectionString"].ConnectionString))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("putinfo", con))
{
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter p1 = new SqlParameter();
p1.ParameterName = "@title";
p1.SqlValue = txtTitle.Text.Trim();
cmd.Parameters.Add(p1);
SqlParameter p2 = new SqlParameter();
p2.ParameterName = "@lei";
p2.SqlValue = DropDownList1.SelectedValue.Trim();
cmd.Parameters.Add(p2);
SqlParameter p3 = new SqlParameter();
p3.ParameterName = "@content";
p3.SqlValue = txtContent.Text.Trim();
cmd.Parameters.Add(p3);
SqlParameter p4 = new SqlParameter();
p4.ParameterName = "@picture";
p4.SqlValue = fupPicture.PostedFile.FileName;
fupPicture.SaveAs(Server.MapPath(pictureFileName));
cmd.Parameters.Add(p4);
cmd.Prepare();
int fetchnum = cmd.ExecuteNonQuery();
if (fetchnum >= 1)
{
Response.Write("<script language=javascript>alent('发布新消息成功!');</script>");
}
else
{
Response.Write("<script language=javascript>alent('发布新消息失败!');</script>");
}
}
}
}
多了一句 fupPicture.SaveAs(Server.MapPath(pictureFileName));这个 展开
恩 上穿图片后 图片保存到某个文件夹中 并储存该图片保存后的路径
在我的代码中修改
protected void btnAdd_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["aspnetdbConnectionString"].ConnectionString))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("putinfo", con))
{
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter p1 = new SqlParameter();
p1.ParameterName = "@title";
p1.SqlValue = txtTitle.Text.Trim();
cmd.Parameters.Add(p1);
SqlParameter p2 = new SqlParameter();
p2.ParameterName = "@lei";
p2.SqlValue = DropDownList1.SelectedValue.Trim();
cmd.Parameters.Add(p2);
SqlParameter p3 = new SqlParameter();
p3.ParameterName = "@content";
p3.SqlValue = txtContent.Text.Trim();
cmd.Parameters.Add(p3);
SqlParameter p4 = new SqlParameter();
p4.ParameterName = "@picture";
p4.SqlValue = fupPicture.PostedFile.FileName;
fupPicture.SaveAs(Server.MapPath(pictureFileName));
cmd.Parameters.Add(p4);
cmd.Prepare();
int fetchnum = cmd.ExecuteNonQuery();
if (fetchnum >= 1)
{
Response.Write("<script language=javascript>alent('发布新消息成功!');</script>");
}
else
{
Response.Write("<script language=javascript>alent('发布新消息失败!');</script>");
}
}
}
}
多了一句 fupPicture.SaveAs(Server.MapPath(pictureFileName));这个 展开
1个回答
展开全部
protected void btnAdd_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["aspnetdbConnectionString"].ConnectionString))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("putinfo", con))
{
string imgPath=""//图片上传路径,如 upload/xxx.jpg
try{
fupPicture.SaveAs(Server.MapPath(imgPath)); //图片上传的代码
}
catch{//上传失败的程序处理}
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter p1 = new SqlParameter();
p1.ParameterName = "@title";
p1.SqlValue = txtTitle.Text.Trim();
cmd.Parameters.Add(p1);
SqlParameter p2 = new SqlParameter();
p2.ParameterName = "@lei";
p2.SqlValue = DropDownList1.SelectedValue.Trim();
cmd.Parameters.Add(p2);
SqlParameter p3 = new SqlParameter();
p3.ParameterName = "@content";
p3.SqlValue = txtContent.Text.Trim();
cmd.Parameters.Add(p3);
SqlParameter p4 = new SqlParameter();
p4.ParameterName = "@picture";
//p4.SqlValue = fupPicture.PostedFile.FileName;
p4.SqlValue = imgPath;//保存了路径
cmd.Parameters.Add(p4);
cmd.Prepare();
int fetchnum = cmd.ExecuteNonQuery();
if (fetchnum >= 1)
{
Response.Write("<script language=javascript>alent('发布新消息成功!');</script>");
}
else
{
Response.Write("<script language=javascript>alent('发布新消息失败!');</script>");
}
}
}
}
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["aspnetdbConnectionString"].ConnectionString))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("putinfo", con))
{
string imgPath=""//图片上传路径,如 upload/xxx.jpg
try{
fupPicture.SaveAs(Server.MapPath(imgPath)); //图片上传的代码
}
catch{//上传失败的程序处理}
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter p1 = new SqlParameter();
p1.ParameterName = "@title";
p1.SqlValue = txtTitle.Text.Trim();
cmd.Parameters.Add(p1);
SqlParameter p2 = new SqlParameter();
p2.ParameterName = "@lei";
p2.SqlValue = DropDownList1.SelectedValue.Trim();
cmd.Parameters.Add(p2);
SqlParameter p3 = new SqlParameter();
p3.ParameterName = "@content";
p3.SqlValue = txtContent.Text.Trim();
cmd.Parameters.Add(p3);
SqlParameter p4 = new SqlParameter();
p4.ParameterName = "@picture";
//p4.SqlValue = fupPicture.PostedFile.FileName;
p4.SqlValue = imgPath;//保存了路径
cmd.Parameters.Add(p4);
cmd.Prepare();
int fetchnum = cmd.ExecuteNonQuery();
if (fetchnum >= 1)
{
Response.Write("<script language=javascript>alent('发布新消息成功!');</script>");
}
else
{
Response.Write("<script language=javascript>alent('发布新消息失败!');</script>");
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询