VB .Net 2008 SQL Server ado主/详细信息 [英] VB .Net 2008 SQL Server ado master/detail

查看:63
本文介绍了VB .Net 2008 SQL Server ado主/详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我想询问如何使用vb net sqldataadapter创建主详细信息表格表单,有没有办法可以使用组件属性?或者我是否必须使用sql的连接语句编写sql命令?



谢谢

Kyriakos

Hello,
I want to ask on how I can create a master detail table form with vb net sqldataadapter, is there a way I can do it with the components properties? or do I have to write an sql command with sql''s join statment?

Thank you
Kyriakos

推荐答案

在不知道你要对这些数据做什么的情况下,可以使用什么控制来显示它,如果你想要每行的详细记录,在没有选择主行的情况下显示,我们只是在猜测。



但是,如果您打算使用DataGridView来尝试实现这一点,那么你会很失望的。不支持在DGV的子表中显示详细信息。



但是,如果您只显示主记录,然后显示单个的详细记录如果选择了master,您只需要检索主记录并显示它们,然后当用户选择其中一个时,您可以进行第二次查询以获取详细信息并在其他控件中显示它们。



如果您在表单上显示某些报告,同时显示所有主记录和详细记录,那么您将不得不以不同的方式编写查询返回相关集合中的两个表。
Without knowing what you''re going to do with that data, liek what control you''re going to use to display this, and if you want the detail records for every row to be displayed without selecting a master row, we''re just guessing.

But, if you''re planning on using the DataGridView to try and achieve this, you''ll be disappointed. Showing details in a subtable in a DGV isn''t supported.

But, if you''re only showing master records and then showing the detail records for a single selected master, you only need to retrieve the master records and show them, then when one of those is selected by the user, you can make a second query to get the details and show them in another control(s) somewhere.

If you''re showing something of a report on your form with all the master and detail records displayed at the same time, then you''ll have to write your query differently to return the two tables in a related set.


首先,我不惜一切代价避免使用设计器,而是希望自己编写所有数据库处理代码。这样,我确切地知道每一段代码正在做什么,并且没有代码隐藏在Designer生成的文件中的某个地方,在我不知情的情况下做事情。



主数据和详细信息的查询结果如何?填充数据集中的表的代码是什么样的?您正在使用单个数据集对象,对吗?添加表之间的关系代码是什么样的?将控件绑定到数据的代码怎么样?



您应该将MasterBindingSource的DataSource设置为DataSet对象,将DataMember属性设置为该名称的DataSet中的主表。然后将DetailsBindingSource.DataSource设置为MasterBindingSource,并将DataMember属性设置为DataSet中详细信息表的名称。
First, I avoid using the Designers at all costs and prefer to write all my database handling code myself. That way, I know EXACTLY what every piece of code is doing and there''s no code hiding somewhere in the Designer generated files doing things without me knowing about it.

What do the queries look like for the master and detail? What does the code look like for populating the tables in the dataset? You ARE using a single dataset object, correct? What does the code look like for adding the relation between the tables? How about the code to bind the controls to data?

You should be setting the DataSource for the MasterBindingSource to the DataSet object and the DataMember property set to the name of the master table in your DataSet. Then you set the DetailsBindingSource.DataSource to the MasterBindingSource and set the DataMember property to the name of the details table in your DataSet.


这篇关于VB .Net 2008 SQL Server ado主/详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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