Đầu tiên là phải thiết kế CSDL, ở đay tôi tạo 1 database mới có tên là Employee
Nội dung trích xuất từ tài liệu:
Lưu trữ và hiển thị hình ảnh trong Database - ASP.NET Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.Lưu trữ và hiển thị hình ảnh trong Database - ASP.NETĐầu tiên là phải thiết kế CSDL, ở đay tôi tạo 1 database mới có tên là Employee? code1 CREATE DATABASE [Employee]2 GO3 USE [Employee]4 GO5 CREATE TABLE EmpDetails (6 empid int IDENTITY NOT NULL,7 empname varchar(20),8 empimg image9 )10B1: Tạo 1 Website mới và Import Namespace System.Data.SqlClient dùng để truy xuất CSDLB2: Vào Design kéo tha 2 Label & 1 Textbox Control + 1 File Upload Control + 1 Image Control (để hiển thị hìnhảnh sau khi Upload)? code 1 2 Save Retrieve Images3 4 5 67 8 9 10 11 12 13 14 1617   19 Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only. 2021 22 23 24 25 26272829B3: Viết sự kiện Click cho btnSubmit? code12 protected void btnSubmit_Click(object sender, EventArgs e)3 {4 SqlConnection connection = null;5 try6 { FileUpload img = (FileUpload)imgUpload;7 Byte[] imgByte = null;8 if (img.HasFile && img.PostedFile != null)9 {10 //To create a PostedFile11 HttpPostedFile File = imgUpload.PostedFile; //Create byte Array with file len12 imgByte = new Byte[File.ContentLength];13 //force the control to load data in array14 File.InputStream.Read(imgByte, 0, File.ContentLength);15 } // Insert the employee name and image into db16 string conn = ConfigurationManager.ConnectionStrings17 [EmployeeConnString].ConnectionString;18 connection = new SqlConnection(conn);1920 connection.Open();21 string sql = INSERT INTO EmpDetails(empname,empimg) VALUES(@enm, @eimg) SELECT @@IDENTITY;22 SqlCommand cmd = new SqlCommand(sql, connection);23 cmd.Parameters.AddWithValue(@enm, txtEName.Text.Trim());24 cmd.Parameters.AddWithValue(@eimg, imgByte);25 int id = Convert.ToInt32(cmd.ExecuteScalar());26 lblResult.Text = String.Format(Employee ID is {0}, id); }27 catch28 {29 lblResult.Text = There was an error;30 } finally31 {32 connection.Close();33 }3435 }3637 Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.38B4: Bạn Click chuột phải vào Website tạo 1 file Generic Handler có tên là ShowImage.ashx chẳng hạn? code using System;1 using System.Configuration;2 using System.Web;3 using System.IO;4 using System.Data; using System.Data.SqlClient;56 public class ShowImage : IHttpHandler7 {8 public void ProcessRequest(HttpContext context)9 {10 Int32 empno; if (context.Request.QueryString[id] != null)11 empno = Convert.ToInt32(context.Request.QueryString[id]);12 else13 throw new ArgumentException(No parameter specified);1415 context.Response.ContentType = image/jpeg;16 Stream strm = ShowEmpImage(empno); byte[] buffer = new byte[4096];17 int byteSeq = strm.Read(buffer, 0, 4096);1819 while (byteSeq > 0)20 {21 context.Response.OutputStream.Write(buffer, 0, byteSeq);22 byteSeq = strm.Read(buffer, 0, 4096); }23 //context.Response.BinaryWrite(buffer);24 }2526 public Stream ShowEmpImage(int empno)27 { string conn = ConfigurationManager. ...
Lưu trữ và hiển thị hình ảnh trong Database - ASP.NET
Số trang: 4
Loại file: pdf
Dung lượng: 119.18 KB
Lượt xem: 16
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Tìm kiếm theo từ khóa liên quan:
tài liệu cơ sở dữ liệu đặc tả cơ sở dữ liệu ứng dụng cơ sở dữ liệu lý thuyết cơ sở dữ liệu tự học cơ sở dữ liệuTài liệu có liên quan:
-
Phân tích thiết kế hệ thống - Biểu đồ trạng thái
20 trang 317 0 0 -
Giáo trình cơ sở dữ liệu quan hệ_3
26 trang 110 0 0 -
Bài giảng Cơ sở dữ liệu: Chương 3 - ThS. Hoàng Mạnh Hà
67 trang 74 0 0 -
Bài giảng cơ sở dữ liệu - chương 1 - ĐH KHTN Tp.HCM
46 trang 53 0 0 -
177 trang 39 0 0
-
Thương mại điện tử: Lối ra cho DN bưu chính?
3 trang 37 0 0 -
0 trang 36 0 0
-
Nhập môn Cơ sở Dữ liệu - Phần 5
51 trang 34 0 0 -
Nhập môn Cơ sở Dữ liệu ( Ths. Phan Võ Minh Thắng ) - Phần 2
64 trang 32 0 0 -
Bài giảng Cơ sở dữ liệu - Bài 5: Chuẩn hóa
28 trang 31 0 0