In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "what is ADO.NET asynchronous query". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The ADO.NET database provider contains Connection, Command, DataAdapter, and DataReader objects. In normal ADO.NET programming, the first step is to create a Connection object and provide it with the information it needs, such as a connection string. Then create a Command object and give it the details of the SQL command to execute. This command can be a built-in SQL text command, a stored procedure, or direct access to the table. If desired, you can also provide parameters for these commands.
After creating the Connection and Command objects, you must determine whether the command returns the result set. If the command does not return a result set, you can execute the command by calling one of several Execute methods. On the other hand, if the command returns a result set, you must determine whether to keep the result set for future use without maintaining a connection to the database. If you want to preserve the result set, you must create a DataAdapter object and populate the DataSet or DataTable object with it. These objects can maintain the information in disconnected mode. However, if you don't want to keep the result set, but just want to execute the command in a quick way, you can use the Command object to create a DataReader object. The DataReader object, which requires a real-time connection to the database, is a forward-only read-only cursor. Let's take a look at an example of using ADO.NET asynchronous queries.
Use ADO.NET asynchronous query and render the query results in the DataGridView of the specified Form
Public Class Asynchronous Private Delegate Sub MainInvoke (ByVal TableItems () As String, ByVal RowCount As Integer) 'delegate Delegate Sub AsyncMethodCaller () Public connstr As String Public cmdstr As String Public frm As Form' specified form Public dgv As DataGridView 'specified datagridview Public statuscontrol As Control' display state controls Public message As String' status prompt text Private Sub CallbackHandler () Using conn As New SqlConnection (connstr), cmd As New SqlCommand (cmdstr) Conn) conn.Open () Using reader As SqlDataReader = cmd.ExecuteReader Dim i As Integer Dim items (dgv.Columns.Count-1) As String While reader.Read () For j As Int32 = 0 To dgv.Columns.Count-1 items (j) = reader (dgv.Columns (j) .HeaderText) Next frm.Invoke (New MainInvoke (AddressOf Addrows), items I) I + = 1 End While End Using conn.Close () End Using End Sub Public Sub getdatabase () Dim caller As New AsyncMethodCaller (AddressOf CallbackHandler) Dim result As IAsyncResult = caller.BeginInvoke (AddressOf StopRead, caller) End Sub Private Sub Addrows (ByVal TableItems () As String, ByVal row As Integer) 'add a new line And show the processing progress dgv.Rows.Add () For i As Int32 = 0 To TableItems.Length-1 dgv.Rows (row) .cells (I). Value = TableItems (I) Next If statuscontrol IsNot Nothing Then statuscontrol.Text = message & row End Sub Private Sub StopRead (ByVal ar As IAsyncResult) Dim caller As AsyncMethodCaller = CType (ar.AsyncState, AsyncMethodCaller) caller.EndInvoke (ar) End Sub End Class
How to use ADO.NET asynchronous query:
DataG.Columns.Add ("number", "number") DataG.Columns.Add ("time", "time") DataG.Columns.Add ("user name", "user name") Dim newselect As New Asynchronous newselect.connstr = "SERVER=x;DATABASE=x;USER=x;PASSWORD=x;Asynchronous Processing=true" newselect.cmdstr = "select * from log" newselect.frm = Me newselect.dgv = DataG newselect.statuscontrol = Me newselect.message = "data retrieval." That's all for newselect.getdatabase () "what is an ADO.NET Asynchronous query?" Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.