BhuvanRam 0 Newbie Poster

hi friends..I am very new C# so please dont mine if anything is wrong in my code. actually i am doing a very small project in c# i.e Employee Tracking System well i completed my project but when i use image i am getting exception called Argument exception.. Actually my image is inserting into database successfully.. but when i am retrieving from database only the first image is displaying , when i click the next button.. when i click again its raising an exception called argument exception.. please help me from this.. Thanks in advance

//Image Variables

        String strFn;
        long filelen;
        byte[] image;

//Browse Button

browse_click
{
            openFileDialog1.ShowDialog(this);
            strFn = openFileDialog1.FileName;
            pictureBox1.Image = Image.FromFile(strFn);
            FileInfo filImage = new FileInfo(strFn);
            filelen = filImage.Length;
            image = new byte[System.Convert.ToInt32(filelen)];
}

//Insert into Database

insert_click
{
                DataRow r;
                r = ds.Tables["Employee"].NewRow();
                r[0] = textBox1.Text;
                r[1] = textBox2.Text;
                r[2] = textBox3.Text;
                r[3] = comboBox1.SelectedItem;
                r[4] = image;
                ds.Tables["Employee"].Rows.Add(r);
                da.Update(ds, "Employee");
                MessageBox.Show("Inserted");
}

//when i click next button

int rno=0;

next_click
{
 test();
 label7.Text = rno.ToString();
rno = rno + 1;
}

public void test()
{

            textBox1.Text = ds.Tables["Employee"].Rows[rno][0].ToString();
            textBox2.Text = ds.Tables["Employee"].Rows[rno][1].ToString();
            textBox3.Text = ds.Tables["Employee"].Rows[rno][2].ToString();
            comboBox1.Text = ds.Tables["Employee"].Rows[rno][3].ToString();

            ////Image 
            byte[] barrimg = (byte[])ds.Tables["Employee"].Rows[rno][4];
            MemoryStream ms = new MemoryStream(barrimg);
            ms.Flush();
            
            pictureBox1.Image = Image.FromStream(ms);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.