我在SQL2000中表info_HandOverCar 中字段carPicture 为 IMAGE类型,我在ASP。NET中读图片的代码如下:
Dim myConnection As New SqlConnection
myConnection.ConnectionString = ConfigurationSettings.AppSettings("connectionstring")
Dim myCommand As New SqlCommand
Dim myReader As SqlDataReader
myCommand.Connection = myConnection
myCommand.CommandText = "select carPicture from info_HandOverCar where BookID='" & thisId & "' order by BookID"
Try
myConnection.Open()
Catch ex As Exception
Session("ErrorMsg") = "<TABLE cellSpacing=0 cellPadding=0 width=750 border=0 align=center><tr><td width=748> <TABLE cellSpacing=1 cellPadding=1 width=505 border=0 align=center bgcolor=CCDAF8> <tr> <td bgcolor=white> <TABLE cellSpacing=1 cellPadding=1 width=100% border=0 align=center> <tr> <td bgcolor=EDF2FC height=24 class=p4 colspan=2> <FONT color=2F59BB><B>错误信息提示</B></FONT> </td> </tr> <tr> <td height=20> </td> </tr> <tr> <td width=35% align=right><IMG SRC=""pic/mistakertu.gif"" WIDTH=""134"" HEIGHT=""129"" BORDER=0 ALT=""""></td> <td class=p5 align=center><font color=red><B>查询错误</B></font><BR><BR></td> </tr> <tr> <td height=20> </td> </tr> </table> </td> </tr> </table><BR><BR><BR>"
Response.Redirect("ErrorInfo.aspx")
Server.ClearError()
Exit Sub
End Try
Try
myReader = myCommand.ExecuteReader
Catch ex As Exception
Session("ErrorMsg") = "<TABLE cellSpacing=0 cellPadding=0 width=750 border=0 align=center><tr><td width=748> <TABLE cellSpacing=1 cellPadding=1 width=505 border=0 align=center bgcolor=CCDAF8> <tr> <td bgcolor=white> <TABLE cellSpacing=1 cellPadding=1 width=100% border=0 align=center> <tr> <td bgcolor=EDF2FC height=24 class=p4 colspan=2> <FONT color=2F59BB><B>错误信息提示</B></FONT> </td> </tr> <tr> <td height=20> </td> </tr> <tr> <td width=35% align=right><IMG SRC=""pic/mistakertu.gif"" WIDTH=""134"" HEIGHT=""129"" BORDER=0 ALT=""""></td> <td class=p5 align=center><font color=red><B>查询错误</B></font><BR><BR></td> </tr> <tr> <td height=20> </td> </tr> </table> </td> </tr> </table><BR><BR><BR>"
Response.Redirect("ErrorInfo.aspx")
Server.ClearError()
Exit Sub
End Try
While myReader.Read
' Response.BinaryWrite(byte(myReader.Item("carPicture")))
Dim image As Byte() = myReader.Item("carPicture")
Dim memStream As New System.IO.MemoryStream(image)
Dim bm As New Bitmap(memStream)
Response.BinaryWrite(image)
End While
myReader.Close()
myConnection.Close()提示的错误信息为:
指定的转换无效。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidCastException: 指定的转换无效。源错误:
行 72: While myReader.Read
行 73: ' Response.BinaryWrite(byte(myReader.Item("carPicture")))
行 74: Dim image As Byte() = myReader.Item("carPicture")
行 75: Dim memStream As New System.IO.MemoryStream(image)
行 76: Dim bm As New Bitmap(memStream)
源文件: C:\Inetpub\wwwroot\MotorVehicleRepair\CarAlarmPicturedipose.aspx.vb 行: 74
各位大哥大姐帮忙分析解决一下,好吗?不胜感激 或QQ交流:378566009
Dim myConnection As New SqlConnection
myConnection.ConnectionString = ConfigurationSettings.AppSettings("connectionstring")
Dim myCommand As New SqlCommand
Dim myReader As SqlDataReader
myCommand.Connection = myConnection
myCommand.CommandText = "select carPicture from info_HandOverCar where BookID='" & thisId & "' order by BookID"
Try
myConnection.Open()
Catch ex As Exception
Session("ErrorMsg") = "<TABLE cellSpacing=0 cellPadding=0 width=750 border=0 align=center><tr><td width=748> <TABLE cellSpacing=1 cellPadding=1 width=505 border=0 align=center bgcolor=CCDAF8> <tr> <td bgcolor=white> <TABLE cellSpacing=1 cellPadding=1 width=100% border=0 align=center> <tr> <td bgcolor=EDF2FC height=24 class=p4 colspan=2> <FONT color=2F59BB><B>错误信息提示</B></FONT> </td> </tr> <tr> <td height=20> </td> </tr> <tr> <td width=35% align=right><IMG SRC=""pic/mistakertu.gif"" WIDTH=""134"" HEIGHT=""129"" BORDER=0 ALT=""""></td> <td class=p5 align=center><font color=red><B>查询错误</B></font><BR><BR></td> </tr> <tr> <td height=20> </td> </tr> </table> </td> </tr> </table><BR><BR><BR>"
Response.Redirect("ErrorInfo.aspx")
Server.ClearError()
Exit Sub
End Try
Try
myReader = myCommand.ExecuteReader
Catch ex As Exception
Session("ErrorMsg") = "<TABLE cellSpacing=0 cellPadding=0 width=750 border=0 align=center><tr><td width=748> <TABLE cellSpacing=1 cellPadding=1 width=505 border=0 align=center bgcolor=CCDAF8> <tr> <td bgcolor=white> <TABLE cellSpacing=1 cellPadding=1 width=100% border=0 align=center> <tr> <td bgcolor=EDF2FC height=24 class=p4 colspan=2> <FONT color=2F59BB><B>错误信息提示</B></FONT> </td> </tr> <tr> <td height=20> </td> </tr> <tr> <td width=35% align=right><IMG SRC=""pic/mistakertu.gif"" WIDTH=""134"" HEIGHT=""129"" BORDER=0 ALT=""""></td> <td class=p5 align=center><font color=red><B>查询错误</B></font><BR><BR></td> </tr> <tr> <td height=20> </td> </tr> </table> </td> </tr> </table><BR><BR><BR>"
Response.Redirect("ErrorInfo.aspx")
Server.ClearError()
Exit Sub
End Try
While myReader.Read
' Response.BinaryWrite(byte(myReader.Item("carPicture")))
Dim image As Byte() = myReader.Item("carPicture")
Dim memStream As New System.IO.MemoryStream(image)
Dim bm As New Bitmap(memStream)
Response.BinaryWrite(image)
End While
myReader.Close()
myConnection.Close()提示的错误信息为:
指定的转换无效。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidCastException: 指定的转换无效。源错误:
行 72: While myReader.Read
行 73: ' Response.BinaryWrite(byte(myReader.Item("carPicture")))
行 74: Dim image As Byte() = myReader.Item("carPicture")
行 75: Dim memStream As New System.IO.MemoryStream(image)
行 76: Dim bm As New Bitmap(memStream)
源文件: C:\Inetpub\wwwroot\MotorVehicleRepair\CarAlarmPicturedipose.aspx.vb 行: 74
各位大哥大姐帮忙分析解决一下,好吗?不胜感激 或QQ交流:378566009
解决方案 »
- 使用母版出现错误?????????
- 关于W3C标准和div的background-color
- 关于asp.net 网站 访问人数统计
- IFRAME传值问题!
- 在后台调用label中的值的问题
- 使用DataGrid,绑定列在Edit时候会变长 ,如何固定每个Cell的长度~~
- 关于asp.net的几个常见问题
- 大家有没有碰到这样事情.....
- ASP.Net配置工具有个问题,请大家进来帮忙解决啊!
- 请教:csdn首页上的程序员健康指数有多高的调查中,调查的结果的那些饼图是怎样做出来的?
- 北京海淀区某公司聘asp.net,delphi 程序员,兼职,熟悉asp.net delphi.
- 服务器切换到Windows2003+IIS6.0后,MailMessage发邮件出问题
另外写图片要用一个专门的aspx来写.前面写了html后面再写bytes不能正确显示图片的