Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use VB.NET database access method to encapsulate into class implementation

Shulou Source: shulou.com Published: 2022-06-02 11:39:32 10月06日 Update

In this issue, the editor will bring you about how to use VB.NET database access methods to encapsulate into classes. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

As we all know, the method to be executed by the thread cannot accept any parameters, and if you want to pass in method-specific conditions, you can put the method in a class, define the properties of the class in the class, and set the properties of the class when needed. then call these properties with methods to implement functions similar to method parameters.

ADO.NET provides a unified programming model and a common set of classes for any type of data access, regardless of the language in which you develop the code. ADO.NET is brand new, but as consistent as possible with ADO, it shifts the programming model from a client / server, connection-based model to a new one that allows disconnected front-ends to download records, work offline, and then reconnect to submit changes. ADO.NET is a common feature of WinForms applications, ASP.NET applications, and Web services. Its functionality can be implemented across LAN and Internet connections, and can be implemented in both stateful and stateless situations.

Here, I would like to share with you some of my experience in my work to help you solve the problems encountered. We use VB.NET database access to encapsulate classes because the generated thread runs outside the main application thread, and .net Framework provides thread isolation, so it is not allowed to manipulate objects in the main application with new threads. The way to * is to wrap the object to be accessed by the thread in a class. Let's create a class that encapsulates properties and VB.NET database access methods:

Public Class dealDataBase Private m_sqlDataAdapter As SqlDataAdapter Private m_table As DataTable Public Property setDataAdapter () As SqlDataAdapter Get setDataAdapter=m_sqlDataAdapter End Get Set (ByVal value As SqlDataAdapter) m_sqlDataAdapter=value End Set End Property Public Property setDataTable () As DataTable Get setDataTable=m_table End Get Set (ByVal value As DataTable) m_DataTable=value End Set End Property Public sub GetDataFromDataBase ()... M_table.Clear () m_sqlDataAdapter.Fill (m_table)... End Sub End Class

Here is the code to create and run the thread:

Dim myDB As New dealDataBase () Dim myThreadStart as ThreadStart Dim myThread as Thread myDB.setDataAdapter=Me.DataAdapter1 'DataAdapter1 is the data adapter defined in this window myDB.setDataTable=Me.DataTable1' DataTable1 is the data table defined in this form. MyThreadStart=New ThreadStart (AddressOf myDB.GetDataFromDataBase) myThread=New Thread (myThreadStart) myThread.Start ()... End Sub above is the editor for you to share how to use the VB.NET database access method encapsulated into the class implementation, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Tags: Methods threads data schemas databases encapsulation properties applications programs applications code content functions parameters objects states forms analysis work programming Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Huawei MySQL Shulou Information Linux