Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have register form,where Users can fill their datas`Name,Surname and so on, and can upload image from computer.After uploading image, when i click on button Register,that user's datas saving in database.Then i have another form where i can see all registered users in metroGrid,but only their Name,Surname,Date,Country and i also have Details button in metroGrid.when i click on Details button,opens another form where i can see user's all data` the image too.Everything is okay,i can see all datas except Image, it gives me error.What's the problem?

This is Register form[^]
This is User's form[^]
This is the form,where i can see user's all datas,and Exception[^]
This is Users table in Database[^]

What I have tried:

 //Upload button click
 private void bunifuImageButton6_Click(object sender, EventArgs e)
        {
            this.op = new OpenFileDialog();
            if (op.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.Image = new Bitmap(op.FileName);
            }
            this.n = Path.GetFileName(op.SafeFileName);
        }
//Register button click
            string a = textBox1.Text;
            string b = textBox2.Text;
            string c = textBox3.Text;
            string d = textBox4.Text;
            string f = textBox5.Text;
            n = pictureBox1.Image.ToString();
            DateTime g = dateTimePicker1.Value;
                using (var context = new Suren_BankEntities())
                {
                    User user = new User()
                    {
                        Name = a,
                        Surname = b,
                        Country = c,
                        Login = d,
                        Password = f,
                        Date = g,
                        Photo = n,
                    };
               }
//MetroGrid's CellContentClick
 private void metroGrid1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int index = metroGrid1.CurrentCell.RowIndex;
            int id = (int)metroGrid1.Rows[index].Cells["Id"].Value;
            if (metroGrid1.Columns[e.ColumnIndex].Name == "Details")
            {
                    UserDatas u = new UserDatas(id);
                    u.Show();
            }
        }

private void UserDatas_Load(object sender, EventArgs e)
        {
            using (var context = new Suren_BankEntities())
            {
                User founded = context.Users.Find(id);
                label20.Text = founded.Name;
                label19.Text = founded.Surname;
                label18.Text = founded.Date.ToString();
                label17.Text = founded.Country;
                label16.Text = founded.CardNumber.ToString();
                label15.Text = founded.Login;
                label14.Text = founded.Password;
                label13.Text = founded.AMD.ToString();
                label12.Text = founded.RUR.ToString();
                label11.Text = founded.USD.ToString();
                pictureBox1.Image = new Bitmap(founded.Photo);
            }
        }
Posted
Updated 16-May-18 15:49pm
Comments
Ravi Bhavnani 16-May-18 18:20pm    
So you're getting a null ref exception. That should be pretty easy to track down by stepping through the code using the debugger.

/ravi

1 solution

n = pictureBox1.Image.ToString();

Using "ToString()" on an image doesn't get you a "binary" of a "photo".

It get you a .NET "class name".

(Not much relating to "images" makes sense after that).
 
Share this answer
 
Comments
Suren97 17-May-18 4:04am    
It gives the same error again

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