C# 使用一个查询的不同数据表?
假设我有两个表,C# 使用一个查询的不同数据表?,c#,ms-access,datatable,dataset,oledb,C#,Ms Access,Datatable,Dataset,Oledb,假设我有两个表,Customer和Customer\u address。从一个查询中填充一个数据表很简单,但是否可以通过一个联接查询填充两个不同的数据表 例如: OleDbDataAdapter adapter = new OleDbDataAdapter(); adapter.SelectCommand = new OleDbCommand("SELECT a.CustomerID, b.CustomerEmail FROM Customer a INNER J
Customer
和Customer\u address
。从一个查询中填充一个数据表很简单,但是否可以通过一个联接查询填充两个不同的数据表
例如:
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = new OleDbCommand("SELECT a.CustomerID, b.CustomerEmail FROM Customer a INNER JOIN Customer_address b ON a.CustomerID = b.CustomerID WHERE a.CustomerID = 3", this.connection);
DataSet ds = new DataSet();
adapter.Fill(ds, "Customer");
现在我在ds.Tables[“Customer”]
中有CustomerID
和CustomerEmail
是否可以在表[“客户”]
中有CustomerID
,在表[“客户地址”]
中有CustomerEmail
,而无需进行两次不同的查询?请查看:
“多个结果集:
如果DataAdapter
遇到多个结果集,它将在数据集中创建多个表。这些表的增量默认名称为TableN
,以“Table”开头“对于表0
。如果表名作为参数传递给Fill方法,则会为表提供一个增量默认名称TableName n
,从TableName 0
的“TableName”开始
因此,不能为第二个表指定正确的表名,因为它是从
Fill
中的单个参数派生而来的。如果要减少已完成的查询数,请尝试将它们聚合到存储过程或其他存储过程中。