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

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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“+

“)“

);

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航