.NET开发

本类阅读TOP10

·NHibernate快速指南(翻译)
·vs.net 2005中文版下载地址收藏
·【小技巧】一个判断session是否过期的小技巧
·VB/ASP 调用 SQL Server 的存储过程
·?dos下编译.net程序找不到csc.exe文件
·通过Web Services上传和下载文件
·学习笔记(补)《.NET框架程序设计(修订版)》--目录
·VB.NET实现DirectDraw9 (2) 动画
·VB.NET实现DirectDraw9 (1) 托管的DDraw
·建站框架规范书之——文件命名

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
ACCESS数据库访问组件(二)

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

ACCESS数据库访问组件(二)ACCESS_Table.cs

using System;

namespace XLang.VideoOnline.Framework.Database.Access
{
 /// <summary>
 /// Summary description for ACCESS_DataTable.
 /// </summary>
 public class DataTable:System.Data.DataTable
 {
  private string _tableName;

  private string _primaryKey;

  public string Name
  {
   get { return _tableName; }
   set { _tableName=value; }
  }


  public string PrimaryKey
  {
   get { return _primaryKey; }
   set { _primaryKey=value; }
  }


  public DataTable()
  {
  }


  public DataTable(string tableName)
  {
   _tableName=tableName;
  }


  public string CreateCommand(Database.Access.DataRow[] rows)
  {
   string temp="CREATE TABLE "+_tableName+"(";
   for(int i=0;i<rows.GetLength(0);i++)
   {
    temp+="["+rows[i].Name+"] "+rows[i].Type+(rows[i].IsNull? ",":" not null,");
   }
   temp+="CONSTRAINT [Index1] PRIMARY KEY (["+rows[0].Name+"]))";
   _primaryKey=rows[0].Name;
   return temp;
  }


  public string InsertCommand(Database.Access.DataRow[] rows)
  {
   string temp="";
   temp="INSERT INTO "+_tableName+" ( ";
   for(int i=0;i<rows.GetLength(0);i++)
   {
    temp+="["+rows[i].Name+"] "+",";
   }
   temp=temp.Substring(0,temp.Length-1);
   temp+=") VALUES(";
   for(int i=0;i<rows.GetLength(0);i++)
   {
    if(rows[i].Type.Equals("boolean"))
     temp+=((rows[i].Value.ToString().ToUpper().Equals("YES"))? "yes":"no")+",";
    else if(rows[i].Type.StartsWith("string")||rows[i].Type.Equals("memo")||
     rows[i].Type.Equals("text")||rows[i].Type.StartsWith("text"))
     temp+="'"+rows[i].Value+"',";
    else if(rows[i].Type.Equals("date"))
     temp+="#"+rows[i].Value+"#,";
    else
     temp+=rows[i].Value+",";
   }
   temp=temp.Substring(0,temp.Length-1);
   temp+=")";
   return temp;
  }


  public string DeleteCommand()
  {
   return "DROP TABLE "+_tableName;
  }


  public string DeleteCommand(string conditions)
  {
   return "DELETE * FROM "+_tableName+" WHERE "+conditions;
  }


  public string UpdateCommand(Database.Access.DataRow[] rows,string conditions)
  {
   string temp="UPDATE  "+_tableName+" SET ";
   temp+=ProsessDifferentDataType(rows);
   temp+=" WHERE "+conditions;
   return temp;
  }


  public string SelectCommand()
  {
   return "SELECT * FROM  "+_tableName;
  }


  public string SelectCommand(string conditions)
  {
   return "SELECT * FROM  "+_tableName +" WHERE "+conditions;
  }


  public string SelectCommand(Database.Access.DataRow[] rows,string conditions)
  {
   string temp="SELECT  ";
   for(int i=0;i<rows.GetLength(0);i++)
   {
    temp+="["+rows[i].Name+"],";
   }
   temp=temp.Substring(0,temp.Length-1);
   temp+=" FROM "+_tableName+" WHERE "+conditions;
   return temp;
  }


  public string JoinCommand(Database.Access.DataRow[] rows,string condition,params string [] tableNames)
  {
   string temp="SELECT  ";
   for(int i=0;i<rows.GetLength(0);i++)
   {
    temp+="["+rows[i].Name+"],";
   }
   temp=temp.Substring(0,temp.Length-1);
   //   temp+=" FROM "+_tableName+" WHERE "+conditions;
   temp+=" FROM ";
   foreach(string table in tableNames)
    temp+=table+",";
   temp=temp.Substring(0,temp.Length-1);

   if(condition!=null)
    temp+=" WHERE "+condition;

   return temp;
  }


  private string ProsessDifferentDataType(Database.Access.DataRow[] rows)
  {
   string temp="";
   for(int i=0;i<rows.GetLength(0);i++)
   {
    if(rows[i].Type.Equals("boolean"))
     temp+="["+rows[i].Name+"] ="+
      ((rows[i].Value.ToString().ToUpper().Equals("YES"))? "yes":"no")
      +",";
    else if(rows[i].Type.StartsWith("string")||rows[i].Type.Equals("memo")||
     rows[i].Type.Equals("text")||rows[i].Type.StartsWith("text"))
     temp+="["+rows[i].Name+"] ='"+rows[i].Value+"',";
    else if(rows[i].Type.Equals("date"))
     temp+="["+rows[i].Name+"] =#"+rows[i].Value+"#,";
    else
     temp+="["+rows[i].Name+"] ="+rows[i].Value+",";

   }
   temp=temp.Substring(0,temp.Length-1);
   return temp;
  }
 }
}




相关文章

相关软件