4 Replies - 351 Views - Last Post: 15 February 2013 - 07:34 AM Rate Topic: -----

#1 Leader2000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 05-February 13

Why I cannot save my picture in my DataBase?

Posted 15 February 2013 - 02:16 AM

Hi!

I wrote this codes to download my pictures. Its works well. Then each time I want I would like to save pictures in my database.
But sound that my saving's codes are wrong and there is a red line on this line:
pictureBox1.Image = dRow.ItemArray.GetValue(3);

I have this message: "Cannot implicitly convert type 'System.Drawing.Image'". An explicit
conversion exists (are you missing a cast?)

Can I have some help...

private void NavigateRecords()
        {
            DataRow dRow = ds1.Tables["Avi"].Rows[inc];
            txtBx_Name.Text = dRow.ItemArray.GetValue(1).ToString();
            txtBx_Birthday.Text = dRow.ItemArray.GetValue(2).ToString();
            pictureBox1.Image = dRow.ItemArray.GetValue(3);
        }



private void btnSave_Click(object sender, EventArgs e)
        {
            DataRow dRow = ds1.Tables["Avi"].NewRow();

            dRow[1] = txtBx_Name.Text;
            dRow[2] = txtBx_Birthday.Text;
            dRow[3] = pictureBox1.Image;

            ds1.Tables["Avi"].Rows.Add(dRow);

            UpdateDB();

            MaxRows = MaxRows + 1;
            inc = MaxRows - 1;

            btnAdd.Enabled = true;
            btnSave.Enabled = false;          

            
        }

private void btnDownload_Click(object sender, EventArgs e)
        {
            string Chosen_File = "";

            openFileDialog1.InitialDirectory = "C:";
            openFileDialog1.Title = "Insert an Image";
            openFileDialog1.FileName = "";
            openFileDialog1.Filter = "JPEG Images|*.jpg|GIF Images|*.gif";

            if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
            {
                MessageBox.Show("Operation Cancelled");
            }
            else
            {
                Chosen_File = openFileDialog1.FileName;
                pictureBox1.Image = Image.FromFile(Chosen_File);
            }


Is This A Good Question/Topic? 0
  • +

Replies To: Why I cannot save my picture in my DataBase?

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8962
  • View blog
  • Posts: 33,586
  • Joined: 12-June 08

Re: Why I cannot save my picture in my DataBase?

Posted 15 February 2013 - 06:14 AM

Moving to c#.
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3485
  • View blog
  • Posts: 10,742
  • Joined: 05-May 12

Re: Why I cannot save my picture in my DataBase?

Posted 15 February 2013 - 06:30 AM

On line 6. GetValue() returns an object. You'll need to reverse the operation that you did to save the image. It could be:
- cast the resulting object to an image; or
- cast the resulting object to a byte array, and then load the image from the byte array; OR
- something else.

Since you didn't show us you saved the image, it's hard for us to guess as to how to restore the image.
Was This Post Helpful? 0
  • +
  • -

#4 Leader2000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 05-February 13

Re: Why I cannot save my picture in my DataBase?

Posted 15 February 2013 - 07:11 AM

This is my codes I wrote to save my image. doenst

private void btnSave_Click(object sender, EventArgs e)  

12         {  

13             DataRow dRow = ds1.Tables["Avi"].NewRow();  

14    

15             dRow[1] = txtBx_Name.Text;  

16             dRow[2] = txtBx_Birthday.Text;  

17             dRow[3] = pictureBox1.Image; //Here 

18    

19             ds1.Tables["Avi"].Rows.Add(dRow);  

20    

21             UpdateDB();  

22    

23             MaxRows = MaxRows + 1;  

24             inc = MaxRows - 1;  

25    

26             btnAdd.Enabled = true;  

27             btnSave.Enabled = false;            

28    

29                

30         }  



Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3485
  • View blog
  • Posts: 10,742
  • Joined: 05-May 12

Re: Why I cannot save my picture in my DataBase?

Posted 15 February 2013 - 07:34 AM

Sorry, I missed that.

I would first just try casting the return value of GetValue() to an Image and see if that works. I'm just amazed that your line 17 works. You must have an awesome database that knows how to serialize images by itself.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1