2016-08-22 73 views
-1

在表中image列存储为0xFF ...如何在vb.net winforms图像框中显示此格式文件?我想下面的代码,但没有工作,显示readtimeout/writetimeout错误..help me..advanced感谢..从vb.net中的SQL Server显示图像框中的图像winforms

Private Sub DisplayNameAttribute_UserImage()  
    Try 
     strimage = "SELECT userimage from MKBLOGIN where empcode='" & str_empcode & "'" 
     imagedatabytes = objcommonvalidation.func_loadUserImage(strimage)  
     mem = New MemoryStream(imagedatabytes)  
     PictureBox1.Image = ToImage(imagedatabytes)  
    Catch ex As Exception 

    End Try 
End Sub 

Public Function func_loadEmpImage(ByVal str_query As String) As Byte() 
    Try 
     Dim ds As New DataSet 
     da = New SqlDataAdapter(str_query, con) 
     da.Fill(ds) 

     If ds.Tables(0).Rows.Count > 0 Then 
      data = New Byte(0) {} 
      data = ds.Tables(0).Rows(0)("userimage") 
     End If 

     Return data.ToArray() 
    Catch ex As Exception 
     Return data.ToArray() 
    End Try 
End Function 

Public Shared Function ToImage(Data As Byte()) As Image 
    If Data Is Nothing Then 
     Return Nothing 
    End If 
    Dim img As Image 
    Using stream As New MemoryStream(Data) 
     Using temp As Image = Image.FromStream(stream) 
      img = New Bitmap(temp) 
     End Using 
    End Using 
    Return img 
End Function 

回答

0
cmd = New SqlCommand("Select userimage from table", con) 
dr = cmd.ExecuteReader 
dr.read 

Dim ImgStream As New IO.MemoryStream(CType(sqldr("userimage"), Byte())) 
PictureBox1.Image = Image.FromStream(ImgStream) 
ImgStream.Dispose() 
+0

其不显示 – Sreevardhan

+0

请更多信息编辑。仅限代码和“尝试这个”的答案是不鼓励的,因为它们不包含可搜索的内容,也不解释为什么有人应该“尝试这个”。我们在这里努力成为知识的资源。 –