当我们使用数据集时,数据表 [英] when we use dataset,datatable

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

问题描述

大家好,



我想知道,当我们使用时



Hi All,

I want to know ,when we use

DataGrid1.datasource=datatable



和什么时候




and when

DataGrid1.datasource=dataset;







它们之间有什么区别。



请帮帮我。



先谢谢。




what is the difference between them.

Please help me.

Thanks in Advance.

推荐答案

一个DataSet可以包含几个DataTable。也可以在数据集中的这些数据表之间建立逻辑关系。所以要保持简单:数据集可以看作是容纳数据表的容器。
A DataSet can contain several DataTables. It''s also possible to lay logical relationships between these datatables in the dataset. So to keep it simple: A dataset can be seen as a container that holds datatables.


同意Amit。添加到他所说的内容:当您将数据集作为数据源分配给数据网格(或任何其他UI控件)时,第一个数据集表(数据集)将充当数据源。



希望有所帮助!
Agree with Amit. Adding to what he said: when you assign dataset as datasource to a datagrid( or any other UI control), the first table( of the dataset) will act as datasource.

Hope that helps!


DataSet和DataTable是ADO.NET编程中的关键组件。这意味着DataTable表示数据库的内存表示形式。我们可以将数据库中的单个表加载到DataTable中并操作内存中的数据。如果我们要仅在单个数据库表中获取数据,DataTable可以用作DataSource并使用它。另一方面,DataSet可以定义DataRelations--它定义了DataTable之间的关系,就像在数据库中的表之间建立外键关系一样。 DataSet本身不包含任何数据。 DataSet包含DataTables(任何数据实际驻留的地方),DataRelations等,但没有数据。



DataSet and DataTable are the key components in ADO.NET programming. This mean that DataTable represents an in memory representation of the database. We can load a single Table from the database into a DataTable and manipulate the data in memory. DataTable can be used as a DataSource and used it if we are going to fetch data in a single database table only. While DataSet on the other hand can define DataRelations - which define the relationship between DataTables, much like a foreign key relationship can be set up between tables in a database. DataSets, themselves DOES NOT Contain any Data. DataSets contain DataTables (which is where any data actually resides),DataRelations, etc, but no data.

SqlDataAdapter a = new SqlDataAdapter;
DataSet s = new DataSet();
a.Fill(s);
foreach (DataRow dr in s.Tables[0].Rows)
  {
    Console.WriteLine(dr[0].ToString());
  }


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

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