科技行者

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

知识库

知识库 安全导航

至顶网软件频道基础软件在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;         

}

}

}

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

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

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