Asp.net access: how to add an auto-incrementing ID returned page 1/3

Source: Internet
Author: User

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 ));
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.