科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道基础软件在c#中实现3层架构(4)

在c#中实现3层架构(4)

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

在c#中实现3层架构(4)

来源:soft6 2008年5月16日

关键字: 架构 实现 C# Windows

  • 评论
  • 分享微博
  • 分享邮件

public DACustomer(BOCustomer cus)

{

// A reference of the business object class

}

//standard dataset function that adds a new customer

public void Add(BOCustomer cus)

{

String str = BuildAddString(cus);

OpenCnn();

//Open command option - cnn parameter is imporant

OleDbCommand cmd = new OleDbCommand(str,cnn);

//execute connection

cmd.ExecuteNonQuery();

// close connection

CloseCnn();

}

//standard dataset function that updates

//details of a customer based on ID

public void Update(BOCustomer cus)

{

OpenCnn();

String selectStr = "UPDATE " + thisTable +

" set " + cus_LName + " = ''" + cus.LName + "''" +

", " + cus_FName + " = ''" + cus.FName + "''" +

", " + cus_Address + " = ''" + cus.Address + "''" +

", " + cus_Tel + " = ''" + cus.Tel + "''" +

" where cus_ID = ''" + cus.cusID + "''";

OleDbCommand cmd = new OleDbCommand(selectStr,cnn);

cmd.ExecuteNonQuery();   

CloseCnn();

}

//standard dataset function that finds and

//return the detail of a customer in a dataset

public DataSet Find(String argStr)

{

DataSet ds=null;

try

{

OpenCnn();     

String selectStr = "select * from " + thisTable +

" where cus_ID = ''" + argStr + "''";

OleDbDataAdapter da =

new OleDbDataAdapter(selectStr,cnn);

ds = new DataSet();

da.Fill(ds,thisTable);

CloseCnn();             

}

catch(Exception e)

{

String Str = e.Message;

}

return ds;

}

private void OpenCnn()

{

// initialise connection

String cnnStr = CnnStr;

cnn = new OleDbConnection(cnnStr);

// open connection

cnn.Open();

}

private void CloseCnn()

{

// 5- step five

cnn.Close();

}      

// just a supporting function that builds

// and return the insert string for dataset.

private String BuildAddString(BOCustomer cus)

{

// these are the constants as

// set in the top of this module.

strTable="Insert into " + thisTable;

strFields=" (" + cus_ID +

"," + cus_LName +

"," + cus_FName +

"," + cus_Address +

"," + cus_Tel + ")";          

//these are the attributes of the

//customer business object.

strValues= " Values ( ''" + cus.cusID +

"'' , ''" + cus.LName +

"'' , ''" + cus.FName +

"'' , ''" + cus.Address +

"'' , ''" + cus.Tel + "'' )";

insertStr = strTable + strFields + strValues;         

return insertStr;         

}

}

}

    • 评论
    • 分享微博
    • 分享邮件
    闂傚倷绶¢崣搴ㄥ窗閺囩偐鏋庨柕蹇嬪灪婵ジ鏌曡箛瀣偓鏍綖閿燂拷

    濠电姷顣介埀顒€鍟块埀顒€缍婇幃妯诲緞閹邦剛鐣洪梺闈浥堥弲婊勬叏濠婂牊鍋ㄦい鏍ㄧ〒閹藉啴鏌熼悜鈺傛珚鐎规洘宀稿畷鍫曞煛閸屾粍娈搁梻浣筋嚃閸ㄤ即宕㈤弽顐ュС闁挎稑瀚崰鍡樸亜閵堝懎濮┑鈽嗗亝濠㈡ê螞濡ゅ懏鍋傛繛鍡樻尭鐎氬鏌嶈閸撶喎顕i渚婄矗濞撴埃鍋撻柣娑欐崌閺屾稑鈹戦崨顕呮▊缂備焦顨呴惌鍌炵嵁鎼淬劌鐒垫い鎺戝鐎氬銇勯弽銊ф噥缂佽妫濋弻鐔碱敇瑜嶉悘鑼磼鏉堛劎绠為柡灞芥喘閺佹劙宕熼鐘虫緰闂佽崵濮抽梽宥夊垂閽樺)锝夊礋椤栨稑娈滈梺纭呮硾椤洟鍩€椤掆偓閿曪妇妲愰弮鍫濈闁绘劕寮Δ鍛厸闁割偒鍋勯悘锕傛煕鐎n偆澧紒鍌涘笧閹瑰嫰鎼圭憴鍕靛晥闂備礁鎼€氱兘宕归柆宥呯;鐎广儱顦伴崕宥夋煕閺囥劌澧ù鐘趁湁闁挎繂妫楅埢鏇㈡煃瑜滈崜姘跺蓟閵娧勵偨闁绘劕顕埢鏇㈡倵閿濆倹娅囨い蹇涗憾閺屾洟宕遍鐔奉伓

    重磅专题
    往期文章
    最新文章