当前位置:编程学习 > C#/ASP.NET >>

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

答案: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“+ “)“ );}

上一个:读取和设置cookie的一个函数
下一个:通用样式化Datagird

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,