Normalization of data: It is the number of times the data is repeated as much as possible to multiple tables as much as possible to minimize the same data. ADO.NET's main object elements: Data Source: Usually refers to a relational database, such as SQL Server, etc., a data supply: providing data warehouse communication, such as ODBC, etc. Connection object: establish a page program and database-driven communication pipe Command object: A tool DataReader / DataSet object containing read and write data instructions: A place that stores read or writes data .NET control: Main refers to
Connection object: Mainly used to connect the data source to open the connection connection string in the connection string through the open () method to include 3 parts of the portion: >> The first part specifies the type of supply or driver to be used // server = LocalHost >> The second part specifies the database // Database = myDatabase >> Part III usually contains security information, including username, password, etc. // uid = foolboy; pwd = mypasswd command object and DataReader: read and modify Data Command Usage: Objcommand = New OLEDBCOMMAND (strsql, objconnection); objdbDataReader = Objcommand.executeReader (); DataReader: Storage Data Reading method DataReader ["Field"] data binding: Yes Create a connection in data sources and data users the process of. Mainly refers to the limitations that bind to DataReader on DataGrid: >> You can only read data, you cannot modify data >> You can only process the data "DataSet can only handle a table DataSet is his alternative or DataTable? ? Their main difference? DataSet and DataTable objects DataSet represent data in the database, different from DataReader it can store several tables and the relationship between them. In use, it is mainly used to use the following 4 objects: >> DataTable: Indicates the table itself >> DataSet: core object, establish an Adhoc relationship between multi-tables, you can associate a line in a table and another table> > DataAdapter: The result is transmitted to the DataSet from the Connection. The Fill () method copies the data to the DataSet, and the update () method uses the data in the DataSet back to the data source. >> DataView: Specific views of DataTables stored in DataSet >> DataGrid:, etc., DataSource, eventually bound to a specific DataView on ADO.NET About SQL Server SQLConnection SQLCommand SqldataAdapter
Data exception handling
Frequently Asked Questions: >> Code contains references to the ADO.NET objects that do not exist >> Code request data for NULL does not exist >> Connection string errors >> Contains non-existing columns or tables >> Nothing provided The correct userid and password >> Code is the use of syntax incorrect SQL statement >> Network problem caused database connection problem processing method: use try .... catch capture error message
Update data method
Question: >> How to update? Our modifications are based on disconnect, if the modified result is written to the database? >> How to handle synchronous updates? What should I do if the two have updated the same data? The result will be covered? DataSet & DataTable & DataRow relations are as follows: ---------------------------------- ---- | DataSet | | | ------------------------- | | | | | | | | ---------------- | | | | | | ---------------- | | | | | | DataRow | | | | | | ------------------------------------- - | | | ------------------------------------ | DATATABLE = Dataset.tables ["TNAME "]; DATAROW = DATATABLE.ROWS; String strfirstname = DATAROW [0] [" firstname "];
The realization of the update here is an update method for datase Dataset, and does not involve update update operations for data sources: 1. Add record (add rings) Add record First need to declare two variables DataTable, DataRow where DataTable needs instance Table DataRow = DataTable.newrow () declare to Table to the specific data set to assign DataRow again, call DataTable.Rows.Add (DATAROW) 2. Modify the record (editing line) first declare One variable DATAROW [] ObjRows is used to store rows to edit Objrows = DataTable.select ("Query Conditions"); if it is a row, you can do ObjRows = DataTable.Rows [3]; then modify it, such as Objrows [0] [Field1] = "" Objrows [0] = "" 3. Delete record as follows DataTable.Rows [5] .delete (); Instead: It should be like this, first declaring a variable DATAROW [] Objrows to store Deleted rows Objrows = DataTable.select ("Query Conditions");