Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to establish ADO.NET SQL statement Retrieval

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to establish ADO.NET SQL sentence retrieval". Many people will encounter such a dilemma in the operation of actual cases, 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!

Populate DataSet with multiple tables

If you use a batch ADO.NET SQL statement to retrieve multiple tables and populate DataSet,*** tables, name them with the table name assigned to the Fill method. The following table is named with the table name assigned to the Fill method plus a number starting at 1 with an increment of 1. For example, if you run the following code:

'Visual Basic Dim da As SqlDataAdapter = New SqlDataAdapter ("SELECT * FROM Customers; SELECT * FROM Orders;", myConnection) Dim ds As DataSet = New DataSet () da.Fill (ds, "Customers") / / C # SqlDataAdapter da = new SqlDataAdapter ("SELECT * FROM Customers; SELECT * FROM Orders;", myConnection); DataSet ds = new DataSet (); da.Fill (ds, "Customers")

The ADO.NET SQL is placed in a DataTable named "Customers". The data from the Orders table is placed in a DataTable named "Customers1". After you populate the DataSet, you can easily change the TableName property of the "Customers1" table to "Orders". However, subsequent padding causes the "Customers" table to be repopulated, the "Orders" table to be ignored, and another "Customers1" table to be created. To remedy this situation, create a DataTableMapping, map "Customers1" to "Orders", and create additional table mappings for other subsequent tables. For example:

'Visual Basic Dim da As SqlDataAdapter = New SqlDataAdapter ("SELECT * FROM Customers; SELECT * FROM Orders;", myConnection) da.TableMappings.Add ("Customers1", "Orders") Dim ds As DataSet = New DataSet () da.Fill (ds, "Customers") / / C # SqlDataAdapter da = new SqlDataAdapter ("SELECT * FROM Customers; SELECT * FROM Orders;", myConnection); da.TableMappings.Add ("Customers1", "Orders"); DataSet ds = new DataSet (); da.Fill (ds, "Customers") This is the end of the content of "how to set up ADO.NET SQL statement retrieval". 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report