HACKIS - Hacking Internet Security
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» Tuyệt Kỹ Đong Giai Chân Kinh (tuyệt Kỹ cua trai)
Hướng save và load image từ database (Winform C) vào control picturebox EmptyThu Aug 23, 2012 5:38 am by Admin

» Tuyệt kỹ cua giai
Hướng save và load image từ database (Winform C) vào control picturebox EmptyThu Aug 23, 2012 5:36 am by Admin

» NETCAT.........
Hướng save và load image từ database (Winform C) vào control picturebox EmptyMon Aug 13, 2012 6:35 am by Admin

» Bảo mật CSDL bằng phương pháp mã hóa.
Hướng save và load image từ database (Winform C) vào control picturebox EmptyTue Apr 17, 2012 10:04 pm by Admin

» Hàm mã hóa MD5 bằng JavaScript
Hướng save và load image từ database (Winform C) vào control picturebox EmptyTue Apr 17, 2012 10:03 pm by Admin

» Giá của món quà
Hướng save và load image từ database (Winform C) vào control picturebox EmptyFri Apr 13, 2012 6:01 am by Admin

» Sẽ chỉ yêu ai?
Hướng save và load image từ database (Winform C) vào control picturebox EmptyFri Apr 13, 2012 6:01 am by Admin

» Cách đọc bảng chữ cái!
Hướng save và load image từ database (Winform C) vào control picturebox EmptyThu Apr 12, 2012 10:37 pm by Admin

» Gắn trojan, keylog, virus vào website, forum
Hướng save và load image từ database (Winform C) vào control picturebox EmptyTue Apr 10, 2012 1:14 am by Admin

Affiliates
free forum


Hướng save và load image từ database (Winform C) vào control picturebox

Go down

Hướng save và load image từ database (Winform C) vào control picturebox Empty Hướng save và load image từ database (Winform C) vào control picturebox

Post  Admin Sat May 28, 2011 7:31 am

Lấy dữ liệu đã lưu biến thành file ảnh để hiển thị vào trong Picturebox

Về giao diện

Hướng save và load image từ database (Winform C) vào control picturebox Untitl10

- Nút chọn file ảnh: Chọn 1 file ảnh để chuẩn bị lưu vào CSDL
- Nút Save: Lưu ảnh vào CSDL
- Nút Load: Lấy ảnh từ CSDL cho vào Picturebox

Câu kết nối CSDL:

Code:
public SqlConnection CreateConnection()
        {
            //get
            {
                //return new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"].ToString());
                return new SqlConnection(@"Data Source=.sqlexpress;Initial Catalog=LTND_DEMO;Integrated Security=True");
            }           
        }

Đoạn code SaveImage


Code:
private void SaveImage(string file)
        {
            FileStream fs= new FileStream(file, FileMode.Open, FileAccess.Read);

            byte[] picbyte = new byte[fs.Length];

            fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));

            fs.Close();

            string query = "insert into ltnd_STORE_IMG(picname,pic) values(@picname, @pic)";

            SqlParameter[] para = new SqlParameter[2];

            para[0]= new SqlParameter("@picname",file.Substring(file.LastIndexOf("\")));

            para[1] = new SqlParameter("@pic",picbyte);
            para[1].SqlDbType = SqlDbType.Image;
            BaseObject b = new BaseObject();
            try
            {
                b.ExcuteUpdateCommand(query, para);
                MessageBox.Show("Đã lưu thành công.");
            }
            catch (SqlException ex)
            {
                MessageBox.Show("Đã có lỗi xảy ra do" ex.Message ".");
            }
        }

Load image

Code:
private void LoadImage(string ID_IMG)
        {
            if (pictureBox2.Image != null)
            {
                pictureBox2.Image.Dispose();
            }

            BaseObject b = new BaseObject();
            DataTable tbl = b.ExecDataTable("select pic from ltnd_STORE_IMG where ID_IMG, null);

            if (tbl != null && tbl.Rows.Count>0)
            {
                FileStream FS1 = new FileStream("image.jpg", FileMode.Create);
                byte[] blob = (byte[])tbl.Rows[0]["pic"];
                FS1.Write(blob, 0, blob.Length);
                FS1.Close();
                FS1 = null;
                pictureBox2.Image = Image.FromFile("image.jpg");
                pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
                pictureBox2.Refresh();
            }

        }
Admin
Admin
Admin

Tổng số bài gửi : 782
Join date : 2009-08-15

https://hackis.forumvi.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum