Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to store the image into the mysql database from C# in windows application.I already do that but after store it's shows into datagridview and i want to fill again the picturebox from the image on using doubleclick event.It makes the file in debug folder and when i double click on same data it shows the error message. How i do it perfectly somebody help me?
This is my code:

C#
private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewCellCollection dr = dataGridView1.CurrentRow.Cells;
            
            string admno = dr[1].Value.ToString();
            savedImageName = dr[1].Value.ToString();
            string []filepath = Directory.GetFiles("C:\\Users\\Awids1\\Documents\\Visual Studio 2008\\Projects\\School Management\\School Management\\bin\\Debug\\"+admno+"");
            if (filepath != null)
            {
                
                    File.Delete(filepath[0]);
            }

            txtAdmissionNo.Text = dr[1].Value.ToString();
            dateTimePicker1.Text = dr[2].Value.ToString();
            txtstudentname.Text = dr[3].Value.ToString();
            txtage.Text = dr[4].Value.ToString();
            string gend = dr[5].Value.ToString();
            if (gend == "Male")
            {
                radioButton1.Checked = true;

            }
            else
            {
                radioButton2.Checked = true;
            }
            txtfathername.Text = dr[6].Value.ToString();
            txtmothername.Text = dr[7].Value.ToString();
            txtguardianname.Text = dr[8].Value.ToString();
            txtpresentaddress.Text = dr[9].Value.ToString();
            txtpermanentadd.Text = dr[10].Value.ToString();
            txtfatherContact.Text = dr[11].Value.ToString();
            txtguardiancontact.Text = dr[12].Value.ToString();
            tabPage1.Show();
            

            MySqlCommand cmd = new MySqlCommand("Select Class,Roll_No,Batch_No,Session_No,Address,Photo from Student_Identification where Addmission_No='"+admno+"'",Connection.Connect_Main());
            MySqlDataReader drw = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
            while (drw.Read())
            {
                txtsidclass.Text = drw.GetString(0);
                txtsidrollno.Text = drw.GetString(1);
                txtsidbatchno.Text = drw.GetString(2);
                txtsidsession.Text = drw.GetString(3);
                txtsidadd.Text = drw.GetString(4);
                FileStream file;
                BinaryWriter bw;
                int bufferSize = 100;
                byte[] outbyte = new byte[bufferSize];
                long retval;
                long startIndex = 0;
                
                file = new FileStream(savedImageName,FileMode.OpenOrCreate,FileAccess.Write);
                bw = new BinaryWriter(file);
                startIndex = 0;
                retval = drw.GetBytes(5,startIndex,outbyte,0,bufferSize);
                while (retval == bufferSize)
                {
                    bw.Write(outbyte);
                    bw.Flush();
                    startIndex += bufferSize;
                    retval = drw.GetBytes(5, startIndex, outbyte, 0, bufferSize);
                }
                bw.Write(outbyte, 0, (int)retval - 1);
                bw.Flush();
                bw.Close();
                file.Close();
                

            }
            curImage = Image.FromFile(savedImageName);
            pictureBox1.Image = curImage;
            pictureBox1.Invalidate();
        }
Posted
Updated 1-May-13 19:31pm
v2
Comments
walterhevedeich 2-May-13 2:34am    
What's the error?
Binit_Bihari 7-May-13 5:20am    
It's store the image file in local debug folder with the particular name and when i try to open again the same record it shows error that is "It's already use by another one".

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