2016-08-16 2 views
-1

내가 정보가 저장됩니다 때 잘 작동 기능 SaveData'GDI + 일반 오류는'

If Not IsNothing(_Image) Then 
    Dim _MemStream As New MemoryStream() 
    _Image.Save(_MemStream, System.Drawing.Imaging.ImageFormat.Jpeg) 
    .Parameters.AddWithValue("@image", _MemStream.ToArray()).SqlDbType = SqlDbType.Image 
Else 
    .Parameters.AddWithValue("@image", Nothing) 
End If 

이 코드를 사용하여 내 데이터베이스에 내 양식에서 이미지를 저장하려면 처음에는하지만 레지스터의 다른 필드를 업데이트하려고하면 gdi+ generic error 오류가 발생하고 출력은 System.Runtime.InteropServices.ExternalException이며 정보를 저장하고 업데이트하는 데 동일한 기능을 사용합니다.

이 문제의 Serching이 page을 발견했으며 상태 설명에 The image was saved with the wrong image format or the image was saved to the same file it was created from.라고 표시되므로 이미지 필드의 데이터가 저장 (업데이트)되도록 보내기 때문에 문제가 발생한다고 생각합니다. 어떻게 해결할 수 있습니까? 나는 정보를 편집하려고 할 때 나는 해결책을 발견

답변

0

좋아, 내가 이것을 사용했다 :

Dim b() As Byte = DataGridView.SelectedCells.Item(10).Value 
Dim ms As New IO.MemoryStream(b) 
PictureBox.Image = Image.FromStream(ms) 
:

Using ms As New IO.MemoryStream(DirectCast(DataGridView.SelectedCells.Item(10).Value, Byte())) 
    PictureBox.Image = Image.FromStream(ms) 
End Using 

을하지만 그 날이 레지스터를 편집 할 수 없습니다 그래서이 함께 노력

두 방법 모두 똑같은 일을하지만 두 번째 방법 만 사용한다고 생각합니다.

관련 문제