簡體   English   中英

如何從Visual Studio將圖像插入數據庫

[英]How to insert image into database from Visual Studio

我有一個在Visual Studio中創建的數據庫表PHOTOS。 它有id(int),filename(字符串)和照片字段類型圖像。 我創建了一個表單,將PictureBox中的當前immage插入到數據庫中。 當然,因為我很缺乏經驗,所以不行。 如何從c#中的picturebox將圖像插入數據庫? 謝謝你的回答,我知道這段代碼是錯的,但我希望它能讓你知道我想做什么。

SqlCeCommand command = new SqlCeCommand("insert  into photos(id, photo ,filename) values (@id, @blob,@filename)", connection);
command.Parameters.AddWithValue("@blob", pictureBox1.Image);//fileBytes);
command.Parameters.AddWithValue("@filename", textBox1.Text);
command.Parameters.AddWithValue("@id", Int32.Parse(textBox2.Text));

您需要將圖像轉換為字節數組以將其插入數據庫。 這里有一個如何做到這一點的線程: 如何在字節數組中轉換圖像除此之外,你已經有了一般的想法。 您只需使用byte []作為參數的值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM