在数据库中存储和显示图象(存储一)

发表于:2007-06-30来源:作者:点击数: 标签:
using System;using System.Data.SqlClient;using System.Data.SqlTypes;using System.IO;string imageFileLocation=“D:images”;string imageFilePrefix=“cereal“;int numberImageFiles=7;string imageFileType=“.gif“;int maxImageSize=10000;SqlConne
using System;using System.Data.SqlClient;using System.Data.SqlTypes;using System.IO;string imageFileLocation=“D:images”;string imageFilePrefix=“cereal“;int numberImageFiles=7;string imageFileType=“.gif“;int maxImageSize=10000;SqlConnection imageConnection=null;SqlCommand imageCommand=null;]//几个要用到的方法;void openConnection() { //create SqlConnection Object imageConnection=new SqlConnection(ConfigurationSettings.AppSettings[“wind“]); //open connection imageConnection.open(); }void closeConnection() { //close the connection imageConnection.Close(); }void createCommand(){imageCommand=new SqlCommand();imageCommand.Connection=imageConnection;}void executeCommand(string commandText){int commandResult;imageCommand.CommandText=commandText;commandResult=imageCommand.ExecuteNonQuery();}void createImageTable(){executeCommand(“IF EXISTS{“+“SELECT TABLE_NAME“+“FROM INFOEMATION_SCHEMA.TABLES“+“WHERE TABLE_NAME=@#imagetable@#“+“) DROP TABLE imagetable“ );executeCommand(“CREATE TABLE imagetable(“+“imagefile NVARCHAR(20),“+“imagedata IMAGE“+ “)“ );}

原文转自:http://www.ltesting.net