Click here to Skip to main content
15,666,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
this is my code:
                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");
                    OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strcon);
                    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));

            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 3.5(2008)
Updated 7-Apr-13 4:04am
[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;

int n = 0;
n = comm.ExecuteNonQuery();

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:[^][^][^]
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