Thanks Mohamoss....
I read so much in this links and get more ideas.
I implement code to save photo and succeed in that.
The code I Implement in C#. [Using OleDbDataAdapter]
Global field to hold the path of the photo: GSPathImage
The function used to get the path of the photo:
private void EmployeePhoto_Click(object sender, System.EventArgs e)
{
System.Windows.Forms.OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Employee Photo";
ofd.Filter = "Bitmap (*.BMP;*.DIB;*.)|*.BMP;*.DIB|JPEG
(*.JPG;*.JPEG;*.JPE;*.JFIF)|*.JPG;*.JPEG;*.JPE;*.JFIF|All files
(*.*)|*.*" ;
ofd.ShowDialog();
pBEmpPhoto.Image = new Bitmap(ofd.FileName) ;
GSPathImage = ofd.FileName ;
}
GSPathImage = GSPathImage == null ? "" : GSPathImage ;
byte[] photo = GSPathImage == "" ? new byte[0]: GetPhoto(GSPathImage) ;
OleDbParameter oledbParam = new OleDbParameter("@ImagEmployee"
,OleDbType.VarBinary,photo.Length,ParameterDirection.Input,true,0,0,null
, DataRowVersion.Current ,photo);
oleDbConnection1.Open();
Example to add values for Employee and his photo:
oleDbDataAdapter1.InsertCommand.CommandText =
"INSERT INTO EmployeeSalary(EmployeeName , ImagEmployee )"+
"VALUES ('"+lsNewEmpName+"' , '@ImagEmployee' )";
oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();
oleDbConnection1.Close();
Till now everything going ok and no exception.
When retrieving the photo I get exception.
The code of the retrieving:
string EmployeeValue = txtBEmployeeName.Text.Trim();
string myOleDBstring = "SELECT EmployeeName , ImagEmployee FROM
EmployeeSalary WHERE EmployeeName = '"+ EmployeeValue +"'";
DataSet dsTest = new DataSet();
OleDbDataAdapter oledbTest = new OleDbDataAdapter(myOleDBstring
,oleDbConnection1);
oledbTest.Fill(dsTest ,"EmployeeSalary");
int testrec = dsTest.Tables["EmployeeSalary"].Rows.Count;
if(testrec > 0 )
{
Byte[] byteBLOBData = new Byte[0];
byteBLOBData =
(Byte[])(dsTest.Tables["EmployeeSalary"].Rows[testrec-1]["ImagEmployee"]
);
MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);
pBEmpPhoto.Image = Image.FromStream(stmBLOBData);
}
And the exception is:
System.ArpumentException: Invalid parameter user.
Thanks for the help.
Bassem