Microsoft Visual Basic.NET is an updated version of Microsoft Visual Basic, which is based on the. NET Framework to make it easy for users to create applications for Microsoft Windows operating systems and networks.
With Visual Basic.NET, you can quickly implement visual development of network applications, network services, Windows applications, and server-side components. In addition, Visual Basic.NET provides Xcopy deployment for Windows applications, and developers no longer need to worry about versioning of DLLs. Visual Basic is now truly an object-oriented and inheritance-enabled language. The Forms Designer supports visual inheritance and includes many new features, such as automatic change of form size, resource localization, and accessibility support. Data-class tools support XML data internally, and data binding uses disconnected data at design time. In addition, Visual Basic.NET is directly based on the. NET, so developers can make the most of all platform features, or with others. NET language interaction.
What I want to tell you about in this article is the introduction of Visual Basic.NET database programming and its related knowledge.
First, introduce Ado.net and odbc.net
Ado. NET, improved by Microsoft ActiveX data Objects (ADO), provides platform interoperability and shrinking data access capabilities, and is an important tool used by Visual Basic.NET for database programming. Ado.net uses some ADO objects, such as Connection and Command objects, and also introduces new objects. The main new Ado.net objects include datasets, DataReader, and DataAdapter.
Odbc. NET is. NET Framework is another useful class library for database development. But, in the. NET FrameWork SDK1.0 version does not contain odbc.net, to use odbc.net please go to the Microsoft Web site download, specific download address: http://msdn.microsoft.com/library/default.asp?url=/ downloads/list/netdevframework.asp (filename is odbc_net.msi) By default, the installation path is "C:Program FileMicrosoft.netodbc.net". The installed component is named Microsoft.Data.Odbc.dll file.
To add an ODBC. NET Data provider:
Start the Visual Basic.NET development environment, select the tools]->[data]->[Custom Toolbox in the menu bar, and in the Customize Toolbox dialog box, select [. NET Framework Components] Click the Browse button, in the C:Program FileMicrosoft.netodbc.net directory, select the Microsoft.Data.Odbc.dll file. Next, when you select OdbcCommand, OdbcCommandBuilder, OdbcConnection, Odbcdataapdater in the Custom toolbox, click OK. Now that you have completed the Visual Add ODBC. NET to the Basic.NET.
Second, the next introduction data provider (Provider)
Ado. NET and Odbc.net provide a total of three data providers, of which Ado.net provides two of the SQL Server. NET data Provider and the OLE DB. NET Data Provider ODBC. NET provides one (the ODBC. NET Data Provider). Table 1 is the three types of data providers and their supported databases:
Data Provider (Provider)
Supported databases
1.The SQL Server. NET Data provider only supports SQL Server7.0 or later
2.The OLE DB. NET Data Provider Access, Oracle, SQL Server, and so on
3.The ODBC. NET Data Provider Access, Oracle, SQL Server, MYSQL, VFP, etc.
Table 13 types of data providers and their supported databases
Third, next on the above several data providers to connect the various databases
1. Connect the database with the SQL Server. NET data Provider
The SQL Server. NET data Provider is a database that uses the SqlConnection class to connect to SQL Server7.0 or later.
The SqlConnection class is located under the namespace System.Data.SqlClient.
Connection code:
Dim SqlConnection1 as Sqlclient.sqlconnection
Dim strconnect as string= "data source= server name; initial catalog= database name; user id=sa;password=;"
Sqlconnection1=new System.Data.SqlClient.SqlConnection (strconnect)
Sqlconnection1.open ' Open database [Page]
Sqlconnection1.close ' Close the connection and release the resource
2. Connect the database with the OLE DB. NET Data Provider
As has already been said, using the OLE DB. NET Data provider access to types of information such as access, Oracle, and SQL Server
Library, so how does it access these databases? The OLE DB. NET Data Provider is passed in the namespace Sy
Stem. The OleDbConnection class under the Data.oledb class library connects these three different types of databases. The following examples illustrate:
1 Connect SQL Server database
Dim OleDbConnection1 as Oledb.oledbconnection
Dim strconnect as sting= "PROVIDER=SQLOLEDB; Persist Security Info=false; Data source= server name; Initial catalog= database name; User Id=sa; password=; "
Oledbconnection1=new System.Data.OleDb.OleDbConnection (strconnect)
2) Connect to an Access database
Suppose the Access database you want to connect to is named "Example.mdb" and is stored in the D:data directory.
Dim OleDbConnection1 as Oledb.oledbconnection
Dim strconnect as sting= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:data example.mdb"
oledbconnection1= New System.Data.OleDb.OleDbConnection (strconnect)
3 Connect Oracle Database
Dim OleDbConnection1 as Oledb.oledbconnection
Dim strconnect as sting= "provider=msdaora;data source= server name; User ID id=; password= password; "
oledbconnection1= New System.Data.OleDb.OleDbConnection (strconnect)
3. Connect the database with the ODBC. NET Data Provider
The ODBC. NET Data Provider Connection database is implemented through the OdbcConnection class, which is located in the namespace