본문 바로가기
Web Program/Asp.net Lecture

이미지를 db에 저장하기

by 현이빈이 2009. 5. 14.
반응형
 // Create a byte[] from the input file
    int len = Upload.PostedFile.ContentLength;
    byte[] image = new byte[len];
    Upload.PostedFile.InputStream.Read (image, 0, len);
    // Insert the image and comment into the database
    SqlConnection connection = new SqlConnection (@"server=test;database=pub;uid=sa;pwd=1234");
    try
    {
        connection.Open ();
        SqlCommand cmd = new SqlCommand ("insert into Image "
          + "(Image, memo) values (@image, @text)", connection);
        cmd.Parameters.Add ("@image", image);
        cmd.Parameters.Add ("@text", "이미니 넣기 테스트");
        cmd.ExecuteNonQuery ();
    }
    finally
    {
        connection.Close ();
    }
 
반응형