タイプ 'System.DBNull'のオブジェクトをタイプして 'System.Byte []'と入力すると、MySQL Image

2016-05-16 4 views
0

Imこの質問について再度お詫び申し上げます... 私はこの質問を簡略化します。 これは私の問題です:タイプ 'System.DBNull'のオブジェクトをタイプして 'System.Byte []'と入力すると、MySQL Image

エラーポイントはあなたの助けのための

Dim stream As New MemoryStream() 
    Dim command As New MySqlCommand("select Imageblob from employeedetail where EmployeeID = '" + TextBoxEmployeeID.Text + "'", cn)   
Dim image As Byte() = DirectCast(command.ExecuteScalar(), Byte()) 
stream.Write(image, 0, image.Length) 

おかげ

Dim image As Byte() = DirectCast(command.ExecuteScalar(), Byte()) 

コードです!

答えて

0

DBNullは、テーブルのフィールドがNULL値の場合にクエリが返すものです。 DBNullオブジェクトを別の型にキャストすることはできません。あなたは、エラー

Dim image As Byte() 
If Not ISDBNull(DirectCast(command.ExecuteScalar(), Byte())) Then image = DirectCast(command.ExecuteScalar(), Byte()) 

に回避するために、次のことを行うことができ、このフィールドのタイプはどうもありがとうございましimage

+0

に割り当てる前にDBNullであれば、単純にチェック!これは私がこの問題を解決するのに役立ちます! :Dもう一度たくさんのp3tchに感謝 –

関連する問題