简体   繁体   English

VB.net最好用于查询变量QUERY或我应该使用DA

[英]VB.net which is better to use for query variable QUERY or should I use DA

Which is better to use for query 1 or 2 give me some tips. 给查询1或2更好的方法是给我一些提示。 I have a gridview that has a lot of info like hundreds. 我有一个GridView,其中包含许多信息,例如数百个。 Which is advisable to use for fast querying the result without lagging 最好将其用于快速查询结果而不会滞后

  1. QUERY = "SELECT * FROM exdb.sample"

OR 要么

  1. DA = New MySqlDataAdapter("SELECT * FROM exdb.sample", dataCNN)

If I am right you are talking about Connected and Disconnected Architecture, 如果我是对的,那么您在谈论的是“连接和断开连接的体系结构”,

Connected Architecture : you have to declare the connection explicitly by using Open(), and close the connection using Close(), and u cn execute commands using different methods like.. ExecuteNonQuery,ExecuteScalar,ExecuteReader etc.. 连接的体系结构:您必须使用Open()显式声明连接,并使用Close()关闭连接,然后使用不同的方法(例如ExecuteNonQuery,ExecuteScalar,ExecuteReader等)执行命令。

Disconnected Architecture: you dont need to define the connections explicitly..SqlDataAdatpter itself can open and closes the connection..and u can use dataset for storing the info. 断开连接的体系结构:您不需要显式定义连接。.SqlDataAdatpter本身可以打开和关闭连接。.您可以使用数据集来存储信息。 temporarily and Fill method was used to execute the commands give in adapter... 临时使用Fill方法执行适配器中给出的命令...

  • When you use DataAdapter , there's no requirement of opening and closing connection. 使用DataAdapter ,不需要打开和关闭连接。 It's done automatically. 它是自动完成的。
  • By keeping connections open for only a minimum period of time, ADO .NET conserves system resources and provides maximum security for databases and also has less impact on system performance. 通过仅在最短时间内打开连接,ADO .NET可以节省系统资源,并为数据库提供最大的安全性,并且对系统性能的影响较小。
  • Only one operation can be performed at a time in connected environment while in dissconnected multiple operations can be performed. 在连接的环境中一次只能执行一个操作,而在断开连接的环境中可以执行多个操作。

But as you said there are hudreds of records in your application I'll suggest to use DataReader (ie Connected Architecture ) as it is faster than DataAdapter (ie Disconnected Architecture ) beacause it is read-only, forward-only stream of data. 但是正如您所说的,您的应用程序中有数百条记录,我建议您使用DataReader (即Connected Architecture ),因为它比DataAdapter (即Disconnected Architecture )要快,因为它是只读的,仅转发的数据流。 I'll suggest you go through this for more information about DataReader and DataAdapter . 我会建议你去通过有关的更多信息DataReaderDataAdapter

First one is a connected architecture where you will loop through all the rows, populate them to a DataTable and attach to your gridview. 第一个是连接的体系结构,您将在其中遍历所有行,将它们填充到DataTable并附加到gridview。

Whereas, second one is disconnected architecture using a data adapter; 第二个是使用数据适配器的断开连接的体系结构。 you maintain the structure in memory. 您在内存中维护结构。

I would go for the second approach, fill the dataset/datatable and bind the same source to gridview. 我将采用第二种方法,填充数据集/数据表并将相同的源绑定到gridview。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM