TAILIEUCHUNG - Lưu trữ và hiển thị hình ảnh trong Database

Lưu trữ và hiển thị hình ảnh trong Database - Đầu tiên là phải thiết kế CSDL, ở đay tôi tạo 1 database mới có tên là Employee code 1 2 3 4 5 6 7 8 9 10 CREATE DATABASE [Employee] GO USE [Employee] GO CREATE TABLE EmpDetails | Lưu trữ và hiên thị hình ảnh trong Database - Đầu tiên là phải thiết kế CSDL ở đay tôi tạo 1 database mới có tên là Employee code 1 2 3 4 5 6 7 8 9 10 B1 Tạo 1 Website mới và Import Namespace dùng để truy xuất CSDL B2 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 CREATE DATABASE Employee GO USE Employee GO CREATE TABLE EmpDetails empid int IDENTITY NOT NULL empname varchar 20 empimg image code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 html xmlns http 1999 xhtml head runat server title Save Retrieve Images title head body form id form1 runat server div asp LabelID lblEmpName runat server Text Employee Name asp Label nbsp nbsp nbsp nbsp asp TextBoxID txtEName runat server asp TextBox br asp LabelID lblImage runat server Text Employee Image asp Label nbsp nbsp nbsp nbsp asp FileUpload ID imgUpload runat server br br asp Button ID btnSubmit runat server onclick btnSubmit_Click Text Submit nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp ForeColor 0066FF asp Label br asp LabelID lblResult 20 21 22 23 24 25 26 27 28 29 B3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 hr asp ImageID Image1 style width 200px Runat server div form body html Viết sự kiện Click cho btnSubmit code protected void btnSubmit Click objectsender EventArgs e SqlConnection connection null try FileUpload img FileUpload imgUpload Byte imgByte null if null To create a PostedFile HttpPostedFile File Create byte Array with file len imgByte new Byte force the control to load data in array imgByte 0 Insert the employee name and image into db string conn EmployeeConnString .ConnectionString connection new SqlConnection conn string sql INSERT INTO EmpDetails empname empimg VALUES @enm

TỪ KHÓA LIÊN QUAN
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.