从数据库中读取图片问题(参照孟子E章上的方法),有的记录能显示,有的显示不出
Dim myConnection As New SqlConnection("data source=(local);initial catalog=vehiclemis;password=;user id=sa;")
Dim myCommand As New SqlCommand
myCommand.Connection = myConnection
If strMode = "Vehicle" Then
myCommand.CommandText = "Select Vphoto from Vehicle Where VehicleID='" + strImageID + "'"
Else
'myCommand.CommandText = "Select PersonImageType, PersonImage from Person Where PersonID=" + strImageID
End If
Try
myConnection.Open()
Dim myDataReader As SqlDataReader
myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
Do While (myDataReader.Read())
'Response.ContentType = "image/pjpeg"
Response.BinaryWrite(CType(myDataReader.Item("Vphoto"), Byte()))
Loop
myConnection.Close()
Catch SQLexc As System.Exception
'Response.Write("Read Failed : " & SQLexc.ToString())
Throw SQLexc
End Try
我有三条记录,一条可以显示出图片,另两条显示不出。跟踪的结果是在Do while语句中就没有进入循环