本文介绍了如何保存,更新删除员工的个人资料图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在员工上传后立即显示其图片,并且还提供了更新或删除其图片的图片.这些图片将存储在数据库中.
所做的努力:(上传页面)
I want to display the picture of Employee as soon as he has Uploaded and also he has the provision of Updating or deleting his Picture.The Images are to be Stored in Database.
Efforts Made:(Upload page)
protected void butSubmit_Click(object sender, EventArgs e)
{
//try
//{
Byte[] imgByte = null;
if(FileUpload1.HasFile && FileUpload1.PostedFile !=null)
{
HttpPostedFile File = FileUpload1.PostedFile;
imgByte = new Byte[File.ContentLength];
File.InputStream.Read(imgByte, 0, File.ContentLength);
}
string cs = ConfigurationManager.ConnectionStrings["master"].ConnectionString;
using( SqlConnection connection = new SqlConnection(cs))
{
connection.Open();
string sql = "INSERT INTO tblImage(image) VALUES(@theImage) SELECT @@IDENTITY";
using (SqlCommand cmd = new SqlCommand(sql, connection))
{
cmd.Parameters.AddWithValue("@theImage", imgByte);
int id = Convert.ToInt32(cmd.ExecuteScalar());
lblStatus.Text = String.Format("Image is Uploaded successfully!! and Image ID is {0}", id);
cmd.Dispose();
}
connection.Close();
connection.Dispose();
}
显示页面:
Display Page:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#Button1").click(function (e) {
$('.display').text(''); //clean div display
var ID = $("#txtID").val();
if (ID.length > 0) {
var newImage = $('<img />');
newImage.attr('src', 'ReadImage.ashx?id=' + ID); // call handler with id
$('.display').append(newImage);
}
e.preventDefault();
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
Display Image<br />
<br />
Id
<asp:TextBox ID="txtID" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Display" />
<br />
<br />
<div class="display"></div>
<br />
<br />
</div>
</form>
Not Satisfied with Coding.
推荐答案
这篇关于如何保存,更新删除员工的个人资料图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!