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

类别:.NET开发 点击:0 评论:0 推荐:

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://com.8s8s.com/it/it42285.htm