asp.net上传图片

//添加
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection userConnection = Connection.getConnection();
        SqlCommand userCommand = new SqlCommand("ajax_insertxiangc", userConnection);
        userCommand.CommandType = CommandType.StoredProcedure;//采用存储过程
        userCommand.Parameters.Add("@user", SqlDbType.VarChar, 50);//存储过程参数
        userCommand.Parameters["@user"].Value = TextBox1.Text;//给参数赋值
        userCommand.Parameters.Add("@mingc", SqlDbType.VarChar, 50);//存储过程参数
        userCommand.Parameters["@mingc"].Value = tb_MingC.Text;//给参数赋值
        userCommand.Parameters.Add("@tupian", SqlDbType.VarChar, 100);//存储过程参数
        userCommand.Parameters["@tupian"].Value = file_TuP.FileName.Trim();//给参数赋值
        userCommand.Connection.Open();//打开连接
        userCommand.ExecuteNonQuery();
        userCommand.Connection.Close();//关闭连接
        HttpPostedFile postedFile = this.file_TuP.PostedFile; //得到要上传文件
        string fileName;
        fileName = System.IO.Path.GetFileName(postedFile.FileName); //文件名称
        if (fileName != "")
        {
            //保存文件到文件夹,地址是当前页面的同一级目录下的files文件夹中
            postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("~/") + fileName);
        }
        Response.Write("<script>alert('提交成功!')</script>");
        GridView1.DataBind();
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章