Click here to Skip to main content
15,914,389 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void btnSubmit_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 PatientImages (Patient_Id,ImageDate,Photo,ImageName)VALUES(" + txtPatientId.Text + ",'" + txtImageDate.Value.ToString("yyyy/MM/dd HH:mm:ss") + "', @Photo ," + txtImageName.Text + ")";
              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");

          }

      }
Posted

1 solution

hey there,

Try adding single quotes around txtImageName.Text.

I would suggest you to use Parameters for all Values as you used @Photo for Photo.

Hope it helps, let me know how it goes.

Azee...
 
Share this answer
 
Comments
[no name] 10-Oct-13 7:14am    
Thnx Azee.. by using Single quotes around txtImageName.text error has been solved. Thnx again.
Azee 10-Oct-13 7:25am    
mark as solution :)

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