Click here to Skip to main content
15,886,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
this is my code:
C#
try
            {
                byte[] imageData = ReadFile(txt_image.Text);
                if (masked_txt_codem.MaskCompleted == false && txt_image.Text ==string.Empty)
                {
                    errorProvider1.SetError(masked_txt_codem, "please ");
                    errorProvider1.SetError(txt_image, "please");
                }
                else
                {
                    errorProvider1.Clear();
                    OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strcon);
                    con.Open();
                    OleDbCommand comm = new OleDbCommand();
                    comm.Connection = con;
                    comm.CommandType = CommandType.Text;

                   comm.CommandText = "UPDATE janbaz set fname='" + txt_name.Text + "' ,lname ='" + txt_famili.Text + "' ,father_name='" + txt_father.Text + "',birth_date='" + masked_birth_date.Text + "',tahsilat='" + txt_tahsilat.Text + "' ,codem='" + masked_txt_codem.Text + "' , codesh='" + txt_codeshean.Text + "' ,place_tavalod='" + txt_address_work.Text +<big> "' ,[image] = @image</big> where codem='" + masked_txt_codem.Text + "'";

                    comm.Parameters.Add(new OleDbParameter("@image", (object)imageData));

                    MessageBox.Show("success");
                    comm.ExecuteNonQuery();
                    con.Close();
                    comm.Dispose();
                }
            }
            catch (ArgumentException)
            {
                errorProvider1.SetError(txt_image, "prob");
            }
when i want update image
i face the following error:

"Could not save; currently locked by another user"
and this error coming from comm.ExecuteNonQuery();
i use access 2007 and c#.net 3.5(2008)
Posted
Updated 7-Apr-13 4:04am
v3
Comments
[no name] 6-Apr-13 19:12pm    
1. Use using blocks for your objects that implement IDisposable.
2. Use parameterized queries for everything not just one parameter. This is an SQL injection attack begging to happen.
3. Where is your error coming from?
[no name] 7-Apr-13 11:30am    
That tells me that your database is open by another user, close it. Are you using Access by any chance? Why would you think that it matters if it's a desktop or web application?
bernova 8-Apr-13 8:59am    
I change the code in form this:

OleDbCommand comm = new OleDbCommand("update azade set fname='" + txt_name_janbaz.Text + "' ,lname ='" + txt_famili_janbaz.Text + "' ,father_name='" + txt_address_home.Text + "' , address_work='" + txt_address_work.Text + "'image=@image where codem='" + masked_txt_codem.Text +"'" , con);

OleDbParameter my = new OleDbParameter("@image", OleDbType.LongVarBinary,imageData.Length);
my.Value= imageData;
comm.Parameters.Add(my);

int n = 0;
n = comm.ExecuteNonQuery();
if(n>0)
{
messagebox.show("yes");
}
con.Close();

but i have same error

1 solution

First of all, if your database is placed in ...\bin\debug or ...\bin\release folder, move it into another folder.
Secondly, you are trying to save image into database, so, please, visit below links:
http://www.c-sharpcorner.com/uploadfile/e628d9/inserting-images-into-ms-access-file-using-oledb/[^]
http://www.setha.info/ict-vb2008/25-ict-vb2008-0003.html[^]
http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/ef838689-5484-4f23-bc3b-ce11c578c524[^]
 
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