Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# MySQL
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)
            {
                
                    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 1-May-13 20:29pm
Edited 1-May-13 20:31pm
(no name)8.1K
v2
Comments
walterhevedeich at 2-May-13 2:34am
   
What's the error?
Member 9974284 at 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
0 Kornfeld Eliyahu Peter 169
1 Zoltán Zörgő 139
2 George Jonsson 135
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 2 May 2013
Copyright © CodeProject, 1999-2014
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