在Web.config中添加以下代码:
然后将Blob字段数据读取到一个字节数组中,从而显示二进制图像。示例代码如下:
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)){ conn.Open(); SqlCommand cmd = new SqlCommand("SELECT Image FROM MyTable", conn); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()){ byte[] blob = reader.GetSqlBinary(0).Value; Response.BinaryWrite(blob); } reader.Close(); conn.Close(); }