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

80酷酷网    80kuku.com

  数据|数据库|显示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“+ “)“ );}

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: