Click here to Skip to main content
13,055,490 members (51,779 online)
Rate this:
Please Sign up or sign in to vote.
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:

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)
            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;
                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();
            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)
                    startIndex += bufferSize;
                    retval = drw.GetBytes(5, startIndex, outbyte, 0, bufferSize);
                bw.Write(outbyte, 0, (int)retval - 1);
            curImage = Image.FromFile(savedImageName);
            pictureBox1.Image = curImage;
Posted 1-May-13 19:29pm
Updated 1-May-13 19:31pm
walterhevedeich 2-May-13 2:34am
What's the error?
Member 9974284 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 2 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100