4, DataSet's DataSet's DataSet's role is to provide a disconnected storage for the data source, without having to care about the data source, and the operation is only available in DataSet. There are three ways to create DataSet: 1, via DataAdapter 2, via the XML file 3, determine the architecture with the manual method, then enter the data line by line. It mainly introduces the first method. DataAdapter is used to connect DataSet to basic data storage, essentially a metallographic object. It includes SelectCommand objects, INSERTCOMMAND objects, UpdateCommand objects, deleteCommand objects. Template code: Dim DataAdpater As New SqldataAdapter ("Select * from stay" DIM DATASET AS New DataSet () DataAdapter.Fill (DataSet) This time the DataSet's table name is default to table If you use a batch query and will result Fill in DataSet defaults to Table, Table1, Table2 ... TableMappings: Table Name Mapping: Generate DataAdapter after the table name mapping DataAdapter.TableMappings.add ("Table", "Customer") DataAdapter.Fill (Dataset) At this time, the aliasing alias will change to Customer (can be used with Table or Customer operations), DataSet.Tables ("Customer") can reference this table or DataAdapter.TableMappings.Add ("AdonEt", "Customer") dataAdapter.Fill (dataSet, "ADONET") column name mapping:. dataAdapter.TableMappings.Add ( "Table", "Customer") dataAdapter.TableMappings ( "Customer") ColumnMappings.Add ( "CustomerID", "ID) dataAdapter. Fill (DataSet, "Customer") After adding a table name mapping in the DataAdapter, there are two tables, a table is the original table, and the other table is a list after the map, and the column name is also mapped, so in Fill When you want to specify which table, you will not display the list name after the map is displayed. In addition, after the table name, you can only specify DataMember to Student when data binding.
Example (Bind to DataGrid) DIM Conn As New SqlConnection ("Data Source = localhost;" & _ "User ID =; password =;") Conn.open () Dim DataAdapter As New SqlDataAdapter ("SELECT) * From student ", conn) conn.close () Dim DataSet As New DataSet DataAdapter.tableMappings.add (" Table "," Student ") DataAPter.TableMappings.add (" student "," student ") // This step is not The province, otherwise it will be prompted when the list map is mapped below. ColumnMappings.Add ("SNO", "Sno") DataApterapter.TableMappings ("student") .ColumnMappings.Add ( "Sname", "name") dataAdapter.TableMappings ( "Student"). ColumnMappings.Add ( "sex", "gender") dataAdapter.TableMappings ( "Student"). ColumnMappings.Add ( "classID" "Class number") DataAdapter.TableMappings ("student"). ColumnMappings.add ("age", "age") DataApterapter.TableMappings ("student"). ColumnMappings.add ("Address", "address") DataApterapter. Fill (Dataset, "Student") DataGrid1.datasource = DataSet Another DataGrid1.DataMember = "Student" is added DataTableMapping mapping method is to create objects and add it to the DataAdapter Dim conn As New SqlConnection ( "data source = localhost; initial catalog = StudentCourse;" & _ "User ID = sa Password = firerainbow; ") Conn.open () Dim DataAdapter As New Sqldataadapter (" Select * from student ", conn) conn.close () Dim DataSet As New DataSet Dim MyMap As New DataTableMapping (" Table ","
")") MyMap.ColumnMappings.add ("SNO", "Learn") MyMap.ColumnMappings.add ("SNAME", "Name") MyMap.ColumnMappings.add ("SEX", "Gender") MyMap.columnMappings. Add (ClassID "," Class Number ") MyMap.ColumnMappings.Add (" Age "," Age ") MyMap.columnMappings.Add (" Address "," Address ") DataApterapter.TableMappings.add (MyMap) DataAptapter.Fill (dataSet, "Table") DataGrid1.DataSource = dataSet DataGrid1.DataMember = "Student" architecture (schema), by adding architecture FillSchema 1, add the primary key customerTable.PrimaryKey = New DataColumn [] {CustomerTable.Columns ( "CustomerID")} (Adding primary keys by arrays) 2, add relationship dataset.reletions.add ("Customers_invoices", Dataset.Tables ("Customerid"), Dataset.Tables ("InvoInces"). Columns ("" Customerid "), True) 3, there are two main constraints: unique constraints, foreign code constraints (ForeignKeyConstraint), the only constraint is divided into deleteRule (cascading), UpdaterUle (cascaded update constraint), AcceptrejectRule (Calling ACCEPTCHANGES or REJECTCHANGES) 4, add triggers to add triggers to 6 DataSet events, Rowchanged, COLU mnChanging, ColumnChanged, RowDeleting, RowDeleted 5, column schema attributes such as adding a column: customerTable.Columns ( "CustomerID") ReadOnly = true or add columns AutoIncrement:.. customerTable.Columns ( "CustomerID") AutoIncrement = true customerTable.Columns ( "Customerid"). AutoincrementSeed = 1 (Legal position) Customertable.columns ("Customerid"). AutoIncremeTep = 1 (Handling Include Length) Maybe someone will say that this is not done in DBMS,
Do you do it so much? This is mainly for efficiency considerations. If the client's error input can be found in the client, it can reduce unnecessary transmission if it is verified without transmitting it to the server. Expression Columns: DIM EXCOLUMN As New Datacolumn ("LINETOTAL") EXCOLUMN.DATATYPE = TypeOf (FLOAT) EXCOLUMN.EXPIPRESSION = "((Price- (Price * Discount)) * Quantity" DataSet.Tables ("items"). Column.Add (Excolumn)