Click here to Skip to main content
15,847,903 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
how to insert image in access database How to show image dynamically in crystal report c#
Posted
Updated 22-May-11 23:32pm
v2

 
Share this answer
 
v3
private void Submit_Click(object sender, EventArgs e)
       {
           byte[] picbyte = System.IO.File.ReadAllBytes(textBox.Text);
           try
           {
               string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\\PIS(ACU).mdb;";
               Con = new OleDbConnection(@constr);
               Con.Open();
               Com = new OleDbCommand();
               Com.Connection = Con;
               Com.CommandText = "INSERT INTO Pics(Patient_Id,ImageDate,Photo)VALUES(" + txtPatientId.Text + ",'" + txtImageDate.Value.ToString("yyyy/MM/dd HH:mm:ss") + "', @Photo)";
               OleDbParameter picParam = Com.Parameters.Add("@Photo", SqlDbType.Binary);
               picParam.Value = picbyte.ToArray();
               picParam.Size = picbyte.ToArray().Length;
               Com.ExecuteNonQuery();
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
           }
           finally
           {
               Con.Close();
               MessageBox.Show("Image Uploaded Successfully", "PIS System");
                DiseaseRecord D = new DiseaseRecord();
                D.Show();
                this.Close();
           }
       }


       private void btnBrowse_Click(object sender, EventArgs e)
       {
           OpenFileDialog fd = new OpenFileDialog();
           fd.InitialDirectory = "c:\\";
          // DialogResult Result = fd.ShowDialog();
           if (fd.ShowDialog() == DialogResult.OK)
           {
               textBox.Text = fd.FileName.ToString();
               pictureBox.ImageLocation = textBox.Text;
           }
           Console.ReadLine();
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900