⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readimage.cs.txt

📁 《圣殿祭司的ASP.NET 2.0开发详解——使用C#》光盘内容.包含了书籍所含的源代码.非常经典的一本asp.net2.0的书籍
💻 TXT
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Data.SqlClient;

/// <summary>
/// ReadImage 的摘要描述
/// </summary>
public class ReadImage
{
	//取得数据库连接设置
	static ConnectionStringSettings connString=ConfigurationManager.ConnectionStrings["NorthwindConnectionString"];

	//从byte 0开始,没有位移78bytes
	public MemoryStream GetImage(string EmployeeID)
	{
		//建立Sql命令
		string strSQL = "Select Photo from Employees where EmployeeID=@paramEmployeeID";
		//建立SqlDataSource
		SqlDataSource sqldsPhoto = new SqlDataSource(connString.ConnectionString, strSQL);
		sqldsPhoto.SelectParameters.Add("paramEmployeeID", TypeCode.Int32, EmployeeID);

		try
		{
			//通过SqlDataSource进行查询
			DataView dv = (DataView)sqldsPhoto.Select(DataSourceSelectArguments.Empty);
			//返回DataView第一个Row的Photo字段数据
			Byte[] PhotoImage = (Byte[])dv[0]["Photo"];
			//返回MemoryStream
			return new MemoryStream(PhotoImage,0, PhotoImage.Length);
		}
		catch
		{
			return null;
		}
	}

	//位移78bytes
	public MemoryStream GetImageOffset(string EmployeeID)
	{
		//建立Sql命令
		string strSQL = "Select Photo from Employees where EmployeeID=@paramEmployeeID";
		//建立SqlDataSource
		SqlDataSource sqldsPhoto = new SqlDataSource(connString.ConnectionString, strSQL);
		sqldsPhoto.SelectParameters.Add("paramEmployeeID",TypeCode.Int32,EmployeeID);

		try
		{
			//通过SqlDataSource进行查询
			DataView dv = (DataView)sqldsPhoto.Select(DataSourceSelectArguments.Empty);
			//返回DataView第一个Row的Photo字段数据
			Byte[] PhotoImage = (Byte[])dv[0]["Photo"];	
			//返回MemoryStream
			return new MemoryStream(PhotoImage,78,PhotoImage.Length-78);
		}
		catch
		{
			return null;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -