I am to save one record to an Access table in one Console application having this
using System;
using System.IO;
... namespace File_upload { class Program { static byte[] ImageToStream(string fileName) { Bitmap image = new Bitmap(fileName); ...} static void Main(string[] args) { OleDbConnection conn = null; string fl_nm; OleDbCommand cmd; ... { fl_nm = "z:\\ID-10033196.jpg"; cmd = new OleDbCommand("insert into prt_display (mod_name,photo_file) values ('Search_Auto',@image)", conn); cmd.Parameters.Add("@image", OleDbType.Binary).Value = ImageToStream(fl_nm); if (cmd.ExecuteNonQuery() >= 1) { Console.WriteLine("Record with the image has been saved."); } else Console.WriteLine("Record is not Saved."); } catch (SqlException ex) { Console.WriteLine("ex 1 "); } catch (Exception ex) { Console.WriteLine("ex 2 "); } finally { conn.Close(); } } } }
but when running the project. I get no message and no record has been created. why?
Many Thanks & Best Regards, Hua Min