数据集和数据表之间的差异 [英] Difference between dataset and datatable

查看:422
本文介绍了数据集和数据表之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨........



我想知道数据集和数据表。



Datatable就像数据库中的单个表,数据集就像包含多个表的数据库。



但是当我编写数据集代码时

Hi........

I wanna know about dataset and datatable.

Datatable is like a single table in database and dataset is like database that contain multiple table.

But when I write code of dataset

SqlDataAdapter da = new SqlDataAdapter("select * from tab5,tab6",con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();







数据集获取表格中的数据。 />


数据表编码




Dataset fetch data both of table.

coding of datatable

SqlDataAdapter da = new SqlDataAdapter("select * from tab5,tab6",con);

DataTable dt = new DataTable();
da.Fill(dt);

GridView1.DataSource = dt;
GridView1.DataBind();







数据表也可以获取表格的数据。 br />


现在我的问题是数据集和数据之间的差异




Datatable also fetch data both of table.

Now my question is that what is diffeence between dataset and datatable

推荐答案

DataSet包含DataTables及其数据集关系(如果在数据库中定义)。使用DataSet与DataGridView允许视图向下钻取到相关表格。



我(以及其他一些有经验的开发人员)不使用DataSet,DataAdapters和DataGridViews用于实际工作。
A DataSet contains DataTables and their relationships (if defined in the database). Using a DataSet with a DataGridView allows the view to "drill down" to related tables.

I (and some other experienced developers) don''t use DataSets, DataAdapters, and DataGridViews for "real work".


DataTable - 认为是一个数据库表。



DataSet - 想想包含所有表格的整个数据库。



=> (暗示)DataSet(数据库)是DataTables(表格)的集合。



注意 - 它们是后端的断开连接架构,你可以在那里进行任何操作,它不会影响数据库,直到你更新它们为止。



还有许多其他功能和性能相关的差异,您可以从Google轻松获得。



您的示例 -

现在,来看你的例子。

你实际上是从一张桌子而不是两张桌子中抽取数据你有一个选择查询。



您已经提到了两个表,但它最终会将结果作为一个表加入。



如果您将尝试从不同表中提取数据的多个select语句,那么您可以看到DataTable将无法保存结果并且DataSet将成功。
DataTable - think as one table of database.

DataSet - think as the whole database consisting of all the tables.

=> (implies) DataSet (database) is a collection of DataTables(tables).

Note - they are disconnected architecture of the backend, where you can do any manipulation and it will not affect the database, until you update them back.

There are many other functionality and performance related differences, which you can easily get from Google.

Your example -
Now, coming to your example.
You are actually pulling data from one table not two as you have one select query.

You have mentioned two tables, but it ultimately gives result as one table by joining them.

If you will try more than one select statements pulling data from different tables, then you can see that DataTable will fail to hold the result and DataSet will succeed.


datatable = single 表包含一些数据

dataset = 多个数据表



Happy Coding!

:)
datatable = single table contain some data
dataset = bunch of multiple Datatables

Happy Coding!
:)


这篇关于数据集和数据表之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆