Monday, November 1, 2010

Application of C # and ADO.NET SQL database application data on visitors

The second Internet Guide: SQL-based database-Sever Q data. One used in this article written by a simple C # example. Connect the data connection is the beginning of the visit, and it has to decide how to connect to the data source. At this point needs to stop setting on the property, (such as ConnectionString), establish contact with the data source. The following lists the key attributes and connection tips. The body of the key attributes:
 
ADO.NET application applications class framework, which allows visitors the data, and for. NET applications using the effective use of procedures to help direct way to obtain the necessary information. In this article, I introduced how to use C # and ADO.NET SQL database applications based on application-Sever visitors data. One used in this article written by a simple C # example.
Connection

The beginning of the data connection is visiting the place and decide how to connect to data source. At this point needs to stop setting on the property, (such as ConnectionString),establish contact with the data source. The following lists the key attributes and connection tips.

Key property
  • ConnectionString: (read / write) used to open the SQL Database Sever the char string.
  • ConnectionTimeout: (read) try to connect the maximum time control.
  • Database: (read) currently connected (or connecting) the database name.
  • DataSource: (read) needs to connect to SQL Sever database instance name.
  • Server Version: (read) connected Sever SQL database version of char string validation for example.
  • State: (read) the current connection status.
Key tips
  • BeginTransaction: (overload) the beginning of a database transaction.
  • ChangeDatabase: the SqlConnection change the current database.
  • Close: Close the database connection.
  • CreateCommand: Creates and returns associated with the SqlConnection SqlCommand object.
  • Open: After set the ConnectionString property to properly open a database connection.
Command
Applied ADO.NET applications stored procedures and SQL commands for the operation of the database statement is very important. Here are the key attributes of the commands and tricks.
The key attributes
  • CommandText: (read / write) T-SQL statement or stored procedure database.
  • CommandTimeout: (read / write) command to run the maximum allowed time control.
  • CommandType: (read / write) to explain the instructions CommandText property value.
  • Connection: (read / write) SqlCommand for example the use of the SqlConnection.
  • Parameters: (Reading) SqlParameterCollection.
  • Transaction: (read / write) SqlCommand command to run the business.
Key tips
  • Cancel: cancel operation SqlCommand command.
  • CreateParameter: Create a new SqlParameter object for example.
  • ExecuteNonQuery: Run T-SQL database and return a statement by the effect of the number of rows.
  • ExecuteReader: (overloaded) Send CommandText to the connection, and the establishment of SqlDataReader.
  • ExecuteScalar: run a query and returns the query result set NO · 1 line NO · 1列value.
  • ExecuteXmlReader: Send CommandText to the connection and the establishment of a the XmlReader object.
  • Prepare not: for example in the SQL Database Sever version created for the command.
Data adapter
DataAdapter object is used to communicate the data source and DataSet objects, so it did not score restored and updated.
Key property
  • AcceptChangesDuringFill: (read / write) value, this value may be called on the instructions in the DataRow AcceptChanges situation, and this time the DataRow has been added to the DataTable.
  • TableMappings: (read) in the data source table and DataTable to help the major mapping between the sets.
Key tips
  • Fill: add and update rows in the DataSet with the DataSet data source in the application match the name on the line to stop matching; and create a named "Table" of the DataTable.
  • FillSchema: Add DataSet to the specified named "Table" of the DataTable, and set the framework specified in the data source to match the outline of the match SchemaType.
  • GetFillParameters: Select command in the Run SQL database, the recovery parameter set by the user.
  • Update: For from the name "Table" of the DataTable in the DataSet, its corresponding action calls the appropriate command, such as: insert, update, and delete and so on.
  •  
Visiting the basis of data
In. NET applications use ADO.NET applications within the application framework application to stop workers, the demand to use the two System.Data namespace one: System.Data.SQLDatabase Client or System.Data.OleDB. Using namespace depends on what the database needs of visitors. If the SQL Database Sever visiting database, the Client should applySystem.Data.SQL database namespace; if visiting for more types of database, applicationSystem.Data.OleDB namespace.

Defines the OleDbConnection, conn's one example. In the ConnectionString property to specify the data source to help persons (Microsoft.JET.OLEDB version 4), and the location and name of the data source (Northwind.mdb S Access database). Next, create a Command object instance and set its CommandText property to the actual SQL database char string. Then open the connection, use the command object's ExecuteScalar tips of the first set of records to return the value, and it appears in the message box. In the try / catch block within the open connection; If an error occurs, a message box error message appears. In the finally block, the source code released connection object.

No comments:

Post a Comment