Reputation: 513
I want to insert image in access table. I have all records in DataTable object which is id, name, city, photo etc. Now I want to insert these records in access table.
I am using c# as programing language and .net framework 3.5.
Thanks.
Upvotes: 1
Views: 3040
Reputation: 12226
something like this should help
var oleDbConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\sample.accdb");
var oleDbCommand = oleDbConnection.CreateCommand();
oleDbCommand.CommandText = "insert into Table1 (Name, Photo) values (@name, @photo)";
oleDbCommand.Parameters.AddWithValue("@name", "MyName");
byte[] yourPhoto = GetYourPhotoFromSomewhere();
oleDbCommand.Parameters.AddWithValue("@photo", yourPhoto);
using (oleDbConnection)
{
oleDbConnection.Open();
oleDbCommand.ExecuteNonQuery();
}
Upvotes: 1
Reputation: 5605
This article on MSDN Forum shows how to read and write image data in MS ACCESS.
You will have to use Image data type for the photo field. While inserting convert the data into byte array and pass as parameters.
Upvotes: 1