2015-06-05 51 views
-3

我想使用搜索按鈕檢索存儲在SQL Server中的圖像(二進制文件)。無效的表達式字節'字節'(C#代碼)

private void *button_*Click(object sender, *Event* e) 
     { 
      SqlConnection con = new SqlConnection(Connect.Connec); 
      SqlCommand command = new SqlCommand(); 
      SqlDataReader reader; 
try 
    { 

if (reader.HasRows) 
    { 
    while (reader.Read()) 
     {    
       picStaffImage.Image = (Image)reader["Image"]; //Get the image 
       ImageConvert.ByteArrayToImage(byte[1] (byteArrayIn)); //Goes to the ImageConvert to retrieve image in byte 
       picStaffImage.Image = (Image)reader[ImageConvert.ByteArrayToImage(byte[1](byteArrayIn))]; 

     cmbStationOptn.Text = (string)reader["StationOfOperation"]; 

         } 
        } 
        reader.Close(); 
        command.Dispose(); 
    } 
} 

類如下:

using System.Drawing.Imaging; 

namespace Dexter 
{ 
    class ImageConvert 
    { 
     public static Image ByteArrayToImage(byte[] byteArrayIn) 
     { 

      using (MemoryStream stream = new MemoryStream(byteArrayIn)) 
      { 
       return Image.FromStream(stream); 
      } 
     } 
    } 
} 

什麼代碼試圖做的是,它是檢索存儲在二進制中的SQL Server數據庫中的圖像。它從二進制轉換回圖像,將其放置在名爲picStaffImage的圖片框中。

這裏我如何保存圖像。

else 
{ 


    Image img = picStaffImage.Image; 
    byte[] arr; 
    ImageConverter converter = new ImageConverter(); 
    arr = (byte[])converter.ConvertTo(img, typeof(byte[])); 
    string pass = " INSERT INTO *table* " + "(Image,Operation)" + 
    "VALUES ('" + txtFullName.Text + "', " + 
    " '"+ arr +"', " + 
    " '" + cmbStationOptn.Text + "') "; 
    command = new SqlCommand(pass,con); 

任何幫助將不勝感激。

+0

哪裏byteArrayIn在點擊處理程序來自和它如何定義的? – Ralf

+0

[如何將Sql Server數據庫中的二進制數據轉換回image.used Memory Stream。它保存,現在試圖從Sql Server中檢索](http://stackoverflow.com/questions/30649043/how-to-convert-bin-data-in-sql-server-database-back-to-image-used-內存STRE) –

回答

相關問題