Computer room Charge System (Personal Edition) basic knowledge--ado.net

Source: Internet
Author: User

This period of time has been doing their own computer room charge system, which encountered a lot of professional knowledge: Sqlconnection,sqlcommand,dataset,datatable,datareader concept is unclear.

The relationship between them has been not very clear, consulted a lot of information, and finally found their provenance--ado.net. Also at this time, more understanding of the relationship between this series of knowledge.


**connection:

database connection string, which includes the server name (SERVER=ZHANGHUI-PC), database name (Database=charge-sys), username (user id=sa), password (password=12356) Example:

<strong><span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" ><strong> public      Conn as New SqlConnection ("Server=zhanghui-pc;database=charge-sys;user Id=sa;password =123456 ") </strong></span></strong>


**command :

after the successful connection with the data, you can use the command object to execute the query, modify, insert, delete commands;

Example:

<strong> Dim cmd as New SqlCommand (SQLSTR, conn)        ' stored procedure application        cmd. CommandText = sqlstr        cmd. CommandType = CommandType.Text        cmd. Parameters.Add (New SqlParameter ("@username", Euser.username))        cmd. Parameters.Add (New SqlParameter ("@password", Euser.password))            ' SqlParameter Add method prevents the injection ' cmd caused by the concatenation of the statements        . Parameters.addrange ((New SqlParameter ("@password1", Duser.password)), ((New SqlParameter ("@password2", Duser.password))        ' SqlParameter  AddRange method        Conn. Open ()        Dim reader as SqlDataReader        reader = cmd. ExecuteReader () </strong>


**datatable:

A DataTable is a data grid control, or it can be understood as a virtual table.


**dataset :

a DataSet object is a representation of the data in memory. It includes multiple DataTable objects, while a DataTable contains columns and rows, just like a table in a normal database.

Example: (the relationship between DataSet and DataTable)

<strong><span style= "color: #333333;" > Dim Sqladapter As SqlDataAdapter        Dim dt As New DataTable        Dim ds As New DataSet        ' give cmd value        cmd. CommandText = Cmdtext        cmd. CommandType = Cmdtype        cmd. Connection = conn        cmd. Parameters.addrange (paras)        sqladapter = New SqlDataAdapter (cmd)                instantiation of adapter object        Try            Sqladapter.fill (ds)            dt = ds. Tables (0)                                           </span><span style= "color: #3333ff;" > (Relationship to DataSet and DataTable) </span><span style= "color: #333333;" >              cmd. Parameters.clear ()        Catch ex as Exception            MsgBox ("Query Failed", CType (vbOKOnly + msgboxstyle.exclamation, MsgBoxStyle), "warning")        finally</span></strong>

**datareader :

The DataReader object allows the developer to obtain the results from the Command object's SELECT statement.

Example:

<strong><span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" ><strong>    Dim reader as SqlDataReader        reader = cmd. ExecuteReader () </strong></span></strong>

ADO is a set of object-oriented class libraries for interacting with data sources . Typically, the data source is a database, but the advent of ADO extends these data sources to text files, Excel tables, or XML files.

Found the ADO, immediately feel that they saw the dawn, not so much confused. At the same time also let oneself realize that the computer room toll system is no longer a simple system, it will let us learn a lot of knowledge.



Reference:ado.net_ Baidu Encyclopedia


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.