Ado. NET Data Processing core technology

Source: Internet
Author: User
Tags mixed ole

1. Introduction

With the birth of Microsoft.NET network-oriented new generation development platform, it provides a brand-new development environment for programmers. The author of my own in the use of Ado.net database programming problems encountered, and we discuss the data operation of the key technologies, procedures and common errors. There may be some reference value for. NET database programmers to avoid similar errors.

The author discusses the SQL Server database mainly on the visualbase.net syntax, but does not discuss the structure of the database itself and how to store it. It's just. NET language programming to discuss how to operate the above database.

2. Connection to the database

In Ado.net, the database must be connected before it is operated on. Ado. NET's data providers are: SQL Server.NET data providers are only highly optimized for SQL Server7.0 and higher SQL Server databases; another seemingly versatile provider of data is OLE Db.net, which handles all data sources compatible with OLE DB. Even for relational databases such as Excel spreadsheets, and enterprise-class relational databases such as Oracle and DB2. The third data provider is odbc.net, and the required source first establishes the DSN, but uses little.

2.1 Using SQL Server.NET Data Provider

= Import Namespaces First: Imsports namespace System. Data.sqlclient

= Create Connection object:

SQL Server provides two authentication modes to secure access to the server: Windows authentication mode and mixed mode.

Windows Authentication Mode:

dim strCn as string= "server=SqlServerName;database=DataBaseName;integrated security=SSP"
Dim mySqlConnection as new SqlConnection(strCn)

In mixed mode:

dim strCn as string= "server= SqlServerName;database= DataBaseName;uid=sa;pwd=sa"
Dim mySqlConnection as new SqlConnection(strCn)

When you are done, be sure to close the SqlConnection object and call the SqlConnection closing or Dispose method. These two forms of connection are not merged together in different net programming books, for. NET programmer Novice may have some confusion. For "SQLServerName", if SQL Server servers are native, you can write "localhost", and if SQL Server servers are not native, it is best to use the IP address to which you want to connect SQL Server servers.

2.2 Using OLE DB. NET Data provider: =首先导入命名空间:

Imsports namespace system.Datat
Imsports namespace system.Datat.OleDb
=创建Connection对象:
<连接Access数据库:
Dim strCn as string ="provider=Microsoft.Jet.OLEDB.4.0;data " &" source=c:DataSourceNorthwind.mdb";
Dim myoleDbConnection As New OleDb.OleDbConnection(strCn)
<连接SQL Server数据库:
Dim strCn As Sting="Provider=SQLOLEDB;Persist Security Info=False;Data Source= SqlServerName;Initial Catalog= DataBaseName;User ID=sa;Password=sa;"
Dim myoleDbConnection As New OleDb.OleDbConnection(strCn)

3. How the database operates

To help illustrate the problem, I set up a test database on the SQL Server database and set up a test table on that database, which is structured as follows:

CREATE TABLE [dbo].[Test] (
       [TestID] [int] IDENTITY (1, 1) NOT NULL ,/*测试编号,自动加一 */
       [TestName] [varchar] (50)  NOT NULL , /*测试项目 */
[TestValue] [float] NOT NULL , /*测试值 */
       [Testdate] [datetime]  NOT NULL , /*测试日期 */
      [TestPerson] [char] (10) NOT NULL ,/*测试人 */
        primary key([TestID])
)

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.