Summary of the content of this article
This article continues the previous article, this section describes all additions and deletions related operations.
1
: Add Data Insert Method
2
: Deleting a data Delete method
3
: Updating the Data Update method
One: Add action
Method Prototypes:
Public bool
Insert ()
Public bool Insert (bool autosetvalue) Public
bool Insert (bool autosetvalue, insertoption option)
Example 1:
using (maction action = new maction (tablenames.users))
{
Action. Set (Users.nickname, "Passing Autumn");//Non-UI type set value
action. Ui. Getfrom (txtusername)//ui type set value
if (action. Insert ())
{
int id=action . Get<int> (users.id);//Retrieve the primary key ID after insertion
}
}
Example 2:[usually only action. Insert (True) one line]
using (maction action = new maction (tablenames.users))
{
action. Set (Users.nickname, "Passing Autumn");//Non-UI type set value
action. Getfrom (txtusername)//ui type set value
action. Ui. Setautoprefix (
"ppt");//Set the control prefix to set multiple
action. Insert (True
)///In addition to the assigned table fields, the values are automatically taken from the request["ppt field".
}
Another: Setautoprefix set automatic prefix method (default 4: null, TXT, DDL, CHB)
method Prototype: public void setautoprefix (string autoprefix, params string[] otherprefix)
Customizable settings multiple prefixes are shown for example:
action. Setautoprefix ("ppt", "Nud", "Lab");
Example 3:
using (maction action = new maction (tablenames.users))
{
return action. Insert (False,insertoption.id
);//after inserting, do not need to retrieve the self-increment ID
}
Insertoption Enumeration Description:
<summary>
The return value option for inserting data
</summary>
public enum Insertoption
{
<summary>
Use this key: after inserting data [MSSQL returns ID, other database does not return ID]
</summary>
None,
<summary>
Use this key: The ID is returned when the data is inserted.
</summary>
Id
<summary>
Use this key: After inserting the data, the data rows are populated with the query based on the return ID. [Default options]
</summary>
Fill,
}
Two: delete operation
Method Prototypes:
Public bool
Delete ()
Public bool Delete (object where
)
Example 1:
using (maction action = new maction (tablenames.users))
{
Action. Delete (1);
}
Example 2:
using (maction action = new maction (tablenames.users))
{
Action. Delete ("the"
);//Bulk Delete
}
Three: Update operation
Method Prototypes:
Public bool
Update ()
Public bool Update (object where
)
Public bool Update (Object where, bool
Autosetvalue)
Example 1:
using (maction action = new maction (tablenames.users))
{
action. Set (Users.password, "http://cyq1162.cnblogs.com"
);
Action. Update (1);//renew password with ID 1
}
Example 2:
using (maction action = new maction (tablenames.users))
{
Action. Set (Users.password, "http://cyq1162.cnblogs.com"
);
Action. Update ("Username= ' passing Autumn '"
);
}
Example 3:
using (maction action = new maction (tablenames.users))
{
action. Set (Users.nickname, "Passing Autumn");//Non-UI type set value
action. Update ("Id=1", True
)///In addition to the assigned table fields, the values are automatically taken from the request["field".
}
Cyq. Data layer Framework CYQ. The data framework uses four maction additions and deletions to change