麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 數(shù)據(jù)庫 > Access > 正文

ACCESS數(shù)據(jù)庫訪問組件(一)

2024-09-07 19:04:57
字體:
供稿:網(wǎng)友
access數(shù)據(jù)庫訪問組件(一)access_database.cs

using system;
using system.data;
using system.data.oledb;
using system.collections;

namespace xlang.videoonline.framework.database.access
{
/// <summary>
/// xlang.videoonline.framework.database is designed for create, update, insert and delete operations.
/// </summary>

public class access
{
private oledbconnection _connection;

private string _connectionstring;

private string _databasename;

private database.access.datatablescollection _tables;

private database.access.dataviewscollection _views;

private datetime _creationtime;

private datetime _lastaccesstime;

private datetime _lastwritetime;

public string name
{
get
{
return _databasename;
}
}


public database.access.datatablescollection tables
{
get
{
return _tables;
}
}


public database.access.dataviewscollection views
{
get
{
return _views;
}
}


public datetime creationtime
{
get
{
return _creationtime;
}
}


public datetime lastaccesstime
{
get
{
return _lastaccesstime;
}
}


public datetime lastwritetime
{
get
{
return _lastwritetime;
}
}


public access()
{
}


public access(string databasename)
{

string delimstr = " ://./";
char [] delimiter = delimstr.tochararray();
string [] split = null;
split=databasename.split(delimiter);

_databasename = split[split.length-2];
_connectionstring = "provider=microsoft.jet.oledb.4.0; data source="+databasename;
_creationtime = system.io.file.getcreationtime(databasename);
_lastaccesstime = system.io.file.getlastaccesstime(databasename);
_lastwritetime = system.io.file.getlastwritetime(databasename);
_connection = new oledbconnection( _connectionstring );

try
{
if(!(_connection.state==connectionstate.open)) _connection.open();

_tables=new database.access.datatablescollection(_connection);
_views=new dataviewscollection(_connection);
}
catch(exception e)
{
system.web.httpcontext.current.response.write("<br><font color=#ff0000>access_database_access:</font>"+e.message+"<br>");
}
finally
{
if(_connection.state==connectionstate.open) _connection.close();
}
}

public bool executecommand(string commandstring,commandtype commandtype)
{

switch(commandtype)
{
case commandtype.create:
return create(commandstring);
case commandtype.delete:
return delete(commandstring);
case commandtype.insert:
return insert(commandstring);
case commandtype.select:
return select(commandstring);
case commandtype.join:
return join(commandstring);
case commandtype.update:
return update(commandstring);
case commandtype.view:
return view(commandstring);
case commandtype.other:
return other(commandstring);
default:
break;
}
return true;
}


private bool create(string commandstring)
{
return createdeleteinsertupdate(commandstring);
}


private bool delete(string commandstring)
{
return createdeleteinsertupdate(commandstring);
}


private bool insert(string commandstring)
{
return createdeleteinsertupdate(commandstring);
}


private bool select(string commandstring)
{
try
{
oledbdataadapter adapter=new oledbdataadapter(commandstring,_connection);

// string tablename=null;
// string delimstr = " ";
// char [] delimiter = delimstr.tochararray();
// string [] split = null;
// split=commandstring.split(delimiter);
// tablename=split[4].trim();

string from="from";
int fromindex=commandstring.indexof(from);
string subcommandstring=commandstring.substring(fromindex+4).trim();
int endindex=subcommandstring.indexof(' ');
string tablename2=null;
if(endindex<0)
tablename2=subcommandstring.substring(0).trim();
else
tablename2=subcommandstring.substring(0,endindex).trim();
//system.web.httpcontext.current.response.write("<br><font color=#ff0000>access_database_select:</font>"+tablename2+"<br>");

_tables[tablenametoindex(tablename2)].clear();
adapter.fill(_tables[tablenametoindex(tablename2)]);

adapter=null;
}
catch(exception e)
{
system.web.httpcontext.current.response.write("<br><font color=#ff0000>access_database_select:</font>"+e.message+"<br>");
return false;
}
finally
{
}
return true;
}


private bool join(string commandstring)
{
try
{
oledbdataadapter adapter=new oledbdataadapter(commandstring,_connection);

// string tablename=null;
// string delimstr = " ";
// char [] delimiter = delimstr.tochararray();
// string [] split = null;
// split=commandstring.split(delimiter);
// tablename=split[4].trim();

// string from="from";
// int fromindex=commandstring.indexof(from);
// string subcommandstring=commandstring.substring(fromindex+4).trim();
// int endindex=subcommandstring.indexof(' ');
// string tablename2=null;
// if(endindex<0)
// tablename2=subcommandstring.substring(0).trim();
// else
// tablename2=subcommandstring.substring(0,endindex).trim();
//system.web.httpcontext.current.response.write("<br><font color=#ff0000>access_database_select:</font>"+tablename2+"<br>");

// _tables[tablenametoindex(tablename2)].clear();
// adapter.fill(_tables[tablenametoindex(tablename2)]);
// if(_tables["temp"]!=null)
// _tables[tablenametoindex("temp")].clear();
// else
// {
// _tables[_tables.count]=new database.access.datatable("temp");
// _tables[tablenametoindex("temp")].clear();
// }

_tables[tablenametoindex("temp")].clear();
adapter.fill(_tables[tablenametoindex("temp")]);

adapter=null;
}
catch(exception e)
{
system.web.httpcontext.current.response.write("<br><font color=#ff0000>access_database_join:</font>"+e.message+"<br>");
return false;
}
finally
{
}
return true;
}


private int tablenametoindex(string tablename)
{
for(int i=0;i<_tables.count;i++)
{
if(_tables[i].name.toupper()==tablename.toupper())
return i;
}
return -1;
}

private int viewnametoindex(string viewname)
{
for(int i=0;i<_tables.count;i++)
{
if(_views[i].name.toupper()==viewname.toupper())
return i;
}
return -1;
}


private bool update(string commandstring)
{
return createdeleteinsertupdate(commandstring);
}


private bool createdeleteinsertupdate(string commandstring)
{
if(!(_connection.state==connectionstate.open)) _connection.open();
// start a local transaction.
oledbtransaction mytrans =_connection.begintransaction();

// enlist the command in the current transaction.
oledbcommand mycommand = _connection.createcommand();
mycommand.transaction = mytrans;

try
{
mycommand.commandtext = commandstring;
mycommand.executenonquery();
mytrans.commit();
}
catch(exception e)
{
try
{
mytrans.rollback();
}
catch (oledbexception ex)
{
if (mytrans.connection != null)
{
//console.writeline("an exception of type " + ex.gettype() +
// " was encountered while attempting to roll back the transaction.");
}
}
return false;
}
finally
{
if(_connection.state==connectionstate.open) _connection.close();
}

return true;
}

private bool view(string commandstring)
{
try
{
string from="from";
int fromindex=commandstring.indexof(from);
string subcommandstring=commandstring.substring(fromindex+4).trim();
int endindex=subcommandstring.indexof(' ');
string viewname=null;
if(endindex<0)
viewname=subcommandstring.substring(0).trim();
else
viewname=subcommandstring.substring(0,endindex).trim();

oledbdataadapter adapter=new oledbdataadapter(commandstring,_connection);

_views[viewnametoindex(viewname)].clear();
adapter.fill(_views[viewnametoindex(viewname)]);

adapter=null;
}
catch(exception e)
{
system.web.httpcontext.current.response.write("<br><font color=#ff0000>access_database_view:</font>"+e.message+"<br>");
return false;
}
finally
{
}
return true;
}



private bool other(string commandstring)
{
return true;
}



}
}


  • 網(wǎng)站運(yùn)營seo文章大全
  • 提供全面的站長運(yùn)營經(jīng)驗(yàn)及seo技術(shù)!
  • 發(fā)表評(píng)論 共有條評(píng)論
    用戶名: 密碼:
    驗(yàn)證碼: 匿名發(fā)表
    主站蜘蛛池模板: 免费国产不卡午夜福在线 | 7777久久香蕉成人影院 | 成人视屏免费看 | av在线中文 | 午夜精品毛片 | 一级做a爰性色毛片免费 | 免费一区二区三区 | 久久精品视频免费观看 | 毛片大全免费看 | 羞羞视频免费观看网站 | 黄色免费播放网站 | 久久99精品久久久久久秒播蜜臀 | 日韩黄色一级视频 | 精品国产一级毛片 | 黄网站色成年大片免费高 | 久久久久久久久久久久久久国产 | 91资源在线观看 | 欧美综合在线观看 | 特级a欧美做爰片毛片 | 中文字幕22页| 国产盼盼私拍福利视频99 | 精品一区二区在线播放 | 国产精品视频一区二区三区四 | 欧美伦理一区二区 | 久久精品国产久精国产 | 久久亚洲线观看视频 | 国产精品一区二区x88av | 最新黄色毛片 | 久久精品av| 国产精品免费大片 | 久久99国产精品久久 | 黑人一区二区三区四区五区 | 午夜视频大全 | 欧美一级毛片大片免费播放 | 成人毛片免费看 | www.17c亚洲蜜桃 | 黄色片一区二区 | 一级网站| 国产流白浆高潮在线观看 | 日韩精品免费看 | 欧美精品一区二区性色 |