datatable创建一个主/从关系
来源:互联网 发布:下载淘宝网到手机 编辑:程序博客网 时间:2024/06/13 21:26
转自:http://www.cnblogs.com/xiaofengfeng/category/291662.html
private
void
GetData()
{
try
{
// Specify a connection string. Replace the given value with a
// valid connection string for a Northwind SQL Server sample
// database accessible to your system.
String connectionString =
"Integrated Security=SSPI;Persist Security Info=False;"
+
"Initial Catalog=Northwind;Data Source=localhost"
;
SqlConnection connection =
new
SqlConnection(connectionString);
// Create a DataSet.
DataSet data =
new
DataSet();
data.Locale = System.Globalization.CultureInfo.InvariantCulture;
// Add data from the Customers table to the DataSet.
SqlDataAdapter masterDataAdapter =
new
SqlDataAdapter(
"select * from Customers"
, connection);
masterDataAdapter.Fill(data,
"Customers"
);
// Add data from the Orders table to the DataSet.
SqlDataAdapter detailsDataAdapter =
new
SqlDataAdapter(
"select * from Orders"
, connection);
detailsDataAdapter.Fill(data,
"Orders"
);
// Establish a relationship between the two tables.
DataRelation relation =
new
DataRelation(
"CustomersOrders"
,
data.Tables[
"Customers"
].Columns[
"CustomerID"
],
data.Tables[
"Orders"
].Columns[
"CustomerID"
]);
data.Relations.Add(relation);
// Bind the master data connector to the Customers table.
masterBindingSource.DataSource = data;
masterBindingSource.DataMember =
"Customers"
;
// Bind the details data connector to the master data connector,
// using the DataRelation name to filter the information in the
// details table based on the current row in the master table.
detailsBindingSource.DataSource = masterBindingSource;
detailsBindingSource.DataMember =
"CustomersOrders"
;
}
catch
(SqlException)
{
MessageBox.Show(
"To run this example, replace the value of the "
+
"connectionString variable with a connection string that is "
+
"valid for your system."
);
}
}
- datatable创建一个主/从关系
- 能否从一个没有读到数据SqlDataReader中创建DataTable
- 从一个DataTable导出至另一个DataTable
- 创建一个DataTable以及遍历DataTable的值
- 从一个datatable复制到另一个
- 如何把一个DataTable中的某列通过表关系加到另外一个DataTable中
- 如何把一个DataTable中的某列通过表关系加到另外一个DataTable中
- 创建 DataTable
- 创建DataTable
- 创建DATATABLE
- 创建DataTable
- 创建datatable
- 创建 DataTable
- 创建datatable
- 创建DataTable
- 创建DataTable
- 创建datatable
- 从已有的DataTable中过滤出一个新的DataTable
- Linux和windows 32位64位 数据类型的内存占用
- 人如旧梦的伤感沉思日志发布:指尖,触碰了回忆
- PHPEclipse搭建PHP开发环境
- java对象类赋值
- Java中的对象赋值!!!! .
- datatable创建一个主/从关系
- 月初伤感日志巨献:爱流逝了,我依旧等你
- 编程生活的开始①(逆序输出四位数)
- python MySQLdb安装和使用
- 自制利息计算器
- WaitForSingleObject 和 WaitForMultipleObjects
- 写给那些分手之后还留在原地的人:伤感日志
- minigui linux 安装与运行
- TSLIB移植