天天看點

CYQ.Data 輕量資料層之路 使用篇四曲 MAction 增删改(十五)

本篇内容概要

本篇繼續上一篇内容,本節介紹所有增删改的相關操作。

1:添加資料 insert方法

2:删除資料 delete方法

3:更新資料 update方法

一:添加操作

方法原型:

public bool insert()

public bool insert(bool autosetvalue)

示例1:

maction action = new maction(tablenames.users);

action.set(users.username, "路過秋天");//或者從控件取值 action.getfrom(txtusername);

action.insert();

action.close();

示例2:

action.setautoprefix("txt");//設定控件字首,可設定多個

action.insert(true);

另:setautoprefix 設定自動字首方法

方法原形:public void setautoprefix(string autoprefix, params string[] otherprefix)

可設定多個字首示例如:

action.setautoprefix("txt","ddl","lab");

二:删除操作

public bool delete()

public bool delete(object where)

action.set(users.id, 1);

action.delete();

action.delete("id=1 or username='路過秋天'");

示例3:

CYQ.Data 輕量資料層之路 使用篇四曲 MAction 增删改(十五)

if (action.fill(1))

{

    //處理其它事情

   if (action.delete())

   {

       action.close();

   }

}

CYQ.Data 輕量資料層之路 使用篇四曲 MAction 增删改(十五)

三:更新操作

public bool update()

public bool update(object where)

public bool update(object where, bool autosetvalue)

action.set(users.password, "http://cyq1162.cnblogs.com");

action.update();//更新userid為1的密碼

action.update("username='路過秋天'");

CYQ.Data 輕量資料層之路 使用篇四曲 MAction 增删改(十五)
CYQ.Data 輕量資料層之路 使用篇四曲 MAction 增删改(十五)

action.setautoprefix("txt");

action.getfrom(txtusername);

action.update("id=1",true);

//說明,除了顯式設定的密碼和從控件取的使用者名,其它沒顯示取值的users表的其它屬性,将從txt為字首的控件取值。

//其它屬性自動擷取值類似:取request["txtfullname"]的值賦給fullname屬性。

CYQ.Data 輕量資料層之路 使用篇四曲 MAction 增删改(十五)

結言:

通過本節說明,應該能掌握對于資料的增删改基礎操作。

如在使用中有不明,請予留言。

附:要麼不開源,既然開源了,就得努力寫好相關的文章,讓對本架構感興趣的讀者有所幫助,至于不感興趣的,勿勿略過即可。 

版權聲明:本文原創發表于部落格園,作者為路過秋天,原文連結:

http://www.cnblogs.com/cyq1162/archive/2010/09/06/1818717.html