在我們寫程序的時候,特別是數據庫應用程序的時候,經常會遇到這樣的情況:對于一個給定的表,寫出這個表對應的類(用一句時髦的話說是實現業務實體類),類的數據成員是所有的字段,并且類含有該表的添加修改刪除等操作。還有,對于一個給定的存儲過程,要完成根據存儲過程存取數據或別的數據庫操作。如下代碼就是我們通常要完成的: 1.表的業務實體化 private int iid ; public int id { get { return iid ; } set { iid = value ; } }
private string strname ; public string name { get { return strname ; } set { strname = value ; } }
private string strcode ; public string code { get { return strcode ; } set { strcode = value ; } }
private string strdescription ; public string description { get { return strdescription ; } set { strdescription = value ; } }
private int ifatherid ; public int fatherid { get { return ifatherid ; } set { ifatherid = value ; } }
private int itype ; public int type { get { return itype ; } set { itype = value ; } }
private int iuserid ; public int userid { get { return iuserid ; } set { iuserid = value ; } }
再看一下存儲過程: public bool exesp_ddms_modify_trx( int aiprsn_trx_no, int aiult_incid_no, int aiprsn_trx_status_cd, datetime adttrx_cmpl_dt, string astremail_addr) { sqlconnection conn = sqlconn.instance().connection ;
string strsql = "select * from sysobjects where (xtype='u' or xtype='p') and category<>2 order by name" ; sqlcommand comm = new sqlcommand(strsql,conn) ;