国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > Access > 正文

ACCESS數據庫訪問組件(一)

2024-09-07 19:04:57
字體:
來源:轉載
供稿:網友
access數據庫訪問組件(一)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;
}



}
}


  • 網站運營seo文章大全
  • 提供全面的站長運營經驗及seo技術!
  • 發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 衢州市| 绿春县| 昌平区| 锡林浩特市| 洛浦县| 光山县| 集贤县| 广汉市| 河北省| 台中市| 五大连池市| 定结县| 金寨县| 五华县| 怀仁县| 贡嘎县| 合作市| 宣威市| 定西市| 灵武市| 巨野县| 郸城县| 会泽县| 肥东县| 新竹市| 磐安县| 大田县| 陆丰市| 资源县| 奎屯市| 白朗县| 定日县| 青神县| 嵊州市| 湖口县| 满洲里市| 阿图什市| 自治县| 宜兴市| 阿克陶县| 台中市|