[MrYoung Tutorial: easy to learn] 1ADONET basics and login module implementation 1-1

Source: Internet
Author: User

I. Overview
This will be the first chapter of the [MrYoung Tutorial: easy to learn] ADONET basics series. It aims to share some usage of ADO. NET in C # for the reference of beginners. In this series of articles, we try to demonstrate C # how to operate the database in the form of examples as much as possible, and each article will correspond to an original video recorded by myself, the video shows how to build each operation step by step.

Database operations should be part of the vast majority of application systems, especially in enterprise applications, article systems, and other fields, therefore, learning database operations well is a basic skill that every programmer should possess.

Of course, before getting started, I assume that the reader already knows the C # syntax (at least the variables, methods, and so on). I will start this series of articles from the most basic database concepts, step by step, I hope that through these articles, you will know how to use ADO. NET is developing its own database system. Limited capacity, a lot of descriptions are not rigorous, and the code writing is not standardized. If there are any mistakes, you are welcome to point out a lot and criticize them.

This section describes how to use VS2008 + SQL SERVER2000 as the development environment and the simple implementation of a login module to understand the use of relational databases and SQL 2000 enterprise managers, ado net basic operations.
Ii. Main Content
2.1 Basic concepts of relational databases.

2.2 Basic SQL statements.

2.3 introduction to the login module.

2.4 ADO. NET basics.
2.5 actual login module.

2.6 conclusion.

2.7 other information.
Iii. Relational databases
3.1 concept: a relational database refers to a database that uses a relational model to organize data. In short, a relational model refers to a two-dimensional table model, and a relational database is a data organization composed of two-dimensional tables and their relationships.

Understanding: in fact, relational databases classify data in actual problems into several simple binary relationships. A single binary relationship can create a relational table (a table in EXCEL, with rows and columns ). It is like the student situation table and student renewal table in the class management system.

Relational databases are currently one of the most widely used databases, such as common SQL server, my SQL, and ORACLE databases.

3.2 common concepts:

Link: it can be understood as a two-dimensional table. Each link has a relational name, that is, the table name. The name of a table.

Tuples: a row in the orders table, which is often called a record in the database. If a student information table contains such a row of data, the name is MrYoung, and the age is 26... This row of data is a tuples.

Attribute: it can be understood as a column in the tables Table, which is often called a field in the database. For example, the name in the student information table is an attribute.
Field: The value range of the attribute, that is, the value limit of a column in the database.

Keywords: A group of attributes that can uniquely identify tuples. A database is often referred to as a primary key. It is composed of one or more columns. If one attribute can be ID, it is an integer, and the system automatically adds 1, it can be used as the primary key, because it is not repeated.


3.3 advantages of relational databases

Easy to understand: the structure of a two-dimensional table is very close to the logic world. The relational model is easier to understand than other models such as mesh and hierarchy.

Easy to use: the general SQL language makes it very convenient to operate relational databases. programmers and even data administrators can operate databases logically without having to understand the underlying implementation.

Easy to maintain: Rich integrity (entity integrity, reference integrity, and user-defined integrity) greatly reduces the probability of data redundancy and data inconsistency.

  

3.4 how to create databases and data tables through Enterprise Manager

 

3.4.1 open the Enterprise Manager, expand to the database row in the left-side tree, right-click the database, and choose create database from the shortcut menu, as shown in

3.4.2 In the Open Database Properties window-General-Name field, enter the database name, for example, "Db_Example". By default, click OK.
 

3.4.3 expand the left database row, find the newly created Db_Example database, right-click the table and choose create table]
 
3.4.4 enter the following information in the new table window.

Here, ID is set as the primary key, right-click the ID line to set the primary key, int represents the integer type, varchar represents the variable-length string type, the maximum is 50, and the id is set as the ID, auto-increment mode. In this way, each time we insert a record into this table, ID is automatically added with 1.

Click the Save button in the pop-up box and enter the name of the table to be saved, for example, "tb_user". In this way, a table is created and displayed in the left Tree.

  

  

3.4.5 after clicking the table on the left, you can view the table we just created on the right. The table type is user, indicating that it is created by ourselves. Many tables created by the system exist, you don't need to worry about it. Right-click the tb_user table we created and select return all rows, and add some records in the window that opens, as shown below. In this way, we have successfully created a database without writing any code, added a data table for it, and added some data to the table, so easy.

 

3.5 Basic SQL statements
3.5.1 query SELECT

Purpose: query the specified record row in the specified table.

Format:

SELECT column name FROM table name Where column name = A Value
 
Example:

Select * from tb_user where username = mryoung
 
In tb_user, to query all records whose username column value is mryoung, * indicates all queried columns. Of course, you can also specify the column name to be queried, separated by commas (,). For example:

Select username, userpassword from tb_user where username = mryoung
The WHERE keyword is followed by the query condition. Multiple conditions can be connected by and, as shown in

Select username, userpassword from tb_user where username = mryoung and userpassword = 123
3.5.2 INSERT

Purpose: Add a data entry to the specified table.
Format

Insert into Table Name (column 1, column 2,...) VALUES (value 1, value 2 ,....)
Example:
 
Insert into tb_user values (mryoung, mryoung)
It indicates that a piece of data is inserted in tb_user, because the column name is not added after the table name. All such shorthand methods require you to fill in the values of each attribute in the brackets behind values, here, username is mryoung and userpassword is mryoung. Because the ID Primary Key column is an auto-increment field, you cannot assign values to the ID. Otherwise, an error is reported.

  

3.5.3 modify UPDATE

Purpose: Modify the value of a specified column of a specified data row in a specified table.

Format:

 

UPDATE table name SET column name = new value WHERE column name = A Value

Example:

 

Update tb_user set username = zhangsan where id = 1

Indicates that the id value of the tb_user table is changed to 1, and the username value is changed to 3.

  

3.5.4 DELETE A DELETE

Purpose: delete specified data based on query conditions.

Format:

 

Delete from table name WHERE column name = Value

Example:

 

Delete from tb_user where username = John

Indicates that the data whose username value is zhangsan is deleted.

3.5.6 how to test the query statement

In SQL server 2000, you can open the query analyzer. In the query analyzer, you can enter an SQL statement for execution. The analyzer will provide the execution result or statement error information.

Iv. Summary
In this article, we first understand the concept of relational databases, then learn how to use the Enterprise Manager to create database tables and add data, and finally understand the basic SQL statements: Query, add, modify, in the next article, we will continue to explain how to implement a login form.


 

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.