First look at the interface:
After adding the database:
The statement to be executed:CopyCodeThe Code is as follows: string name _ = This. tbxusename. Text. Trim ();
String webname _ = This. tbxwebname. Text. Trim ();
String URL _ = This. tbxurl. Text. Trim ();
Addfielditem ("news_title", name _);
Addfielditem ("news_source", webname _);
Addfielditem ("news_anthor", URL _);
Common. salert ("added successfully. The added ID is" + insert ("db_news"). tostring ());
After reading the data inserted by Confucius CMS, I felt that the. NET level was still in ASP. The following code is used:
It should be noted that Confucius CMS uses a multi-layer architecture during insertion, and this articleArticleThe main focus is on learning, so I have not made it into multiple layers. The parameterized process is used during insertion, similar to the SQL stored procedure. It is very easy to insert data in practical applications, as shown in the code above.
First, let's talk about a class [dbkeyitem]:Copy codeThe Code is as follows: // <summary>
/// Field attribute in the data table: field name and Field Value
/// </Summary>
Public class dbkeyitem
{
/// <Summary>
/// Field name
/// </Summary>
Public String fieldname;
/// <Summary>
/// Field Value
/// </Summary>
Public String fieldvalue;
Public dbkeyitem (string _ fieldname, object _ fieldvalue)
{
This. fieldname = _ fieldname;
This. fieldvalue = _ fieldvalue. tostring ();
}
}
This class contains two attributes:
1. fieldname: field name
2. fieldvalue: Field Value
This class is mainly used:Copy codeThe Code is as follows: protected arraylist alfielditems = new arraylist (10 );
/// <Summary>
/// Add a field/value pair to the array
/// </Summary>
Public void addfielditem (string _ fieldname, object _ fieldvalue)
{
_ Fieldname = "[" + _ fieldname + "]";
// Traverse to check whether a field name already exists
For (INT I = 0; I <this. alfielditems. Count; I ++)
{
If (dbkeyitem) This. alfielditems [I]). fieldname = _ fieldname)
{
Throw new argumentexception ("the field already exists ");
}
}
This. alfielditems. Add (New dbkeyitem (_ fieldname, _ fieldvalue ));
}