如何在数据集中绑定2个表 [英] How to bind 2 tables in dataset

查看:79
本文介绍了如何在数据集中绑定2个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个表,使用子查询我要从两个表中检索某些字段.此后,我想使用dataadapter填充方法将数据存储在数据集中.在此填充必须指定哪个表名?
任何人都可以帮助我...

解决方案

多个SELECT 语句可以在单个请求中发送到数据库服务器.这里的问题是从查询生成的表具有自动名称Table Table1.但是,可以将生成的表名称映射到应在DataSet中使用的名称.

SqlDataAdapter adapter = new SqlDataAdapter(
    "SELECT * FROM Customers; SELECT * FROM Orders", connection);
adapter.TableMappings.Add("Table", "Customer");
adapter.TableMappings.Add("Table1", "Order");

adapter.Fill(ds);


您可以指定任何名称.指定与数据库中相同的名称不是强制性的.所以,

 myAdapter.Fill(myDataset," );  
基本上,此表名称将帮助您检索前端中的值.


I have a 2 tables,using sub queries i am retrieving some fields from both tables.after that i want to store the data in dataset using dataadapter fill method.while filling here which Table name has to specify?
any one help me...

解决方案

Multiple SELECT statements can be sent to the database server in a single request. The problem here is that the tables generated from the queries have automatic names Table and Table1. However, the generated table names can be mapped to names that should be used in the DataSet.

SqlDataAdapter adapter = new SqlDataAdapter(
    "SELECT * FROM Customers; SELECT * FROM Orders", connection);
adapter.TableMappings.Add("Table", "Customer");
adapter.TableMappings.Add("Table1", "Order");

adapter.Fill(ds);


You can specify any name. It''s not mandatory to specify the same name as in database. So,

myAdapter.Fill(myDataset, "AnyTableName");


Basically, this table name would help you in retrieving the values in your frontend.


这篇关于如何在数据集中绑定2个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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