Skip to content

Read and save image in sql server

iza zain

Asked Oct 10, 2006, 8:27 PM EDT4 answers
Share
LinkedInX
hye, i tried the example to read and save image in sql server, but i got "specified cast is not valid"
can someone please help me to solve this? where to put the temporary image? i put it in debug folder but it didnt work

4 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    hello
    please tell one thing that do u want to save the image (in binary format) or u just want to save images in a folder in urproject and save the url in the database and retrive the image through that url.

    If want the 1st case,then take data type image. and then save that image.

    hope this will help you
    0
  • 0
    i want to save in database (varbinary) and retrieve back from the database. My code is like this:

    C#
    // Get the picture from the DataRow and assign it to
    // a byte array
    byte[] MyPicture = null;
    MyPicture = (byte[])dsFlashcard.Tables[0].Rows[0]["Picture"];
    int ArraySize = new int();
    ArraySize = MyPicture.GetUpperBound(0);
    
    // After retrieving the byte array, I get the number of elements of
    // the array for use in writing the array
    FileStream fsFlashcard = new FileStream("tmp.gif", FileMode.OpenOrCreate, FileAccess.Write);
    // Create a filestream for writing the byte array to a gif
    // file (my picture format - .gif)
    fsFlashcard.Write(MyPicture,0,ArraySize+1);
    fsFlashcard.Close();
    
    // Assign the temporary gif file to the picture box
    picFlashcard.Image = new Bitmap("tmp.gif");
    0
  • 0
    Pls check out this link http://www.aspfree.com/c/a/ASP.NET/Uploading-Images-to-a-Database--C---Part-I/
    0
  • 0
    http://www.atalasoft.com/kb/article.aspx?id=10018
    0