2013-10-08 49 views
-4

後,我公司開發的Windows應用程序進行掃描images.After掃描圖像,我想不直接保存到數據庫在本地計算機上如何圖像保存到數據庫...這我的代碼採用的是如下被掃描

try 
{ 
    String str = string.Empty; 
    WIA.CommonDialogClass scanner; 
    ImageFile imageObject; 

    scanner = new CommonDialogClass(); 
    imageObject = scanner.ShowAcquireImage 
     (WiaDeviceType.ScannerDeviceType, 
     WiaImageIntent.ColorIntent, 
     WiaImageBias.MinimizeSize, 
     ImageFormat.Jpeg.Guid.ToString("B"), 
     false, 
     true, 
     true); 

    str = DateTime.Now.ToString(); 
    str = str.Replace("/", ""); 
    str = str.Replace(":", ""); 
    Directory.CreateDirectory("D:\\scanned1"); 
    //   MessageBox.Show(string.Format("File Extension = {0}\n 
    //\nFormat = {1}", imageObject.FileExtension, imageObject.FormatID)); 
    imageObject.SaveFile(@"D:\scanned1\lel" + str + ".jpg"); 
    MessageBox.Show("Scanning Done"); 
} 
catch (Exception ex) 
{ 
    MessageBox.Show("Please check if the scanner is connected properly."); 
} 

相反,它保存到d驅動的,我想將其保存到數據庫.....我該怎麼辦呢?PLZ回覆...

+0

SQL數據庫... –

+0

你有什麼問題?你有沒有與數據庫交互的問題? – Tomtom

回答

1

我沒有知道什麼「鏡像文件」是真的,但應該把它改造成字節數組(byte [])的方式。然後你需要插入陣列VARBINARY場在SQL。 這樣的事情:

using(SqlCommand cmd = new SqlCommand("INSERT INTO MyTable (myvarbinarycolumn) VALUES (@myvarbinaryvalue)", conn)) 
{ 
    cmd.Parameters.Add("@myvarbinaryvalue", SqlDbType.VarBinary, myarray.length).Value = myarray; 
    cmd.ExecuteNonQuery(); 
} 

ofc sqlcommand應該打開並且有效。 myArray的是一個類型的byte []

+0

嘿格奧爾基Smirnov..The圖像以.jpg格式保存...我需要將其轉換爲字節格式 –

+0

看看http://edulorenzo.wordpress.com/2010/07/16/cast-wia-鏡像文件到系統的繪圖,圖像/在那裏,你可以看到,如何將其轉換爲字節數組 – Tomtom