本文介绍了在亲子关系中发现子串.............的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我想在两个表中创建父子关系,并根据需要显示它们.我的代码是这样的:

Hello everybody,
I want to create parent-child relationship in two tables and to display them as needed. my code is like this :

General master = new General();
字符串str;
str ="SELECT * FROM master";
  master.getdata(str,"parent","ID");
str =从子表中选择*";
master.getdata(str,``child'',``ID'');
DataRelation newrelation =新DataRelation("myrelation",General.DS.Tables [父"] .Columns ["id"],General.DS.Tables [子"] .Columns ["masterid"] );
General.DS.Relations.Add(newrelation);
listBox1.DataSource = General.DS.Tables ["parent"];
listBox1.DisplayMember ="Master_name";

General master = new General();
string str;
str = "SELECT * FROM master";
 master.getdata(str, "parent", "ID");
str="select * from childtable";
master.getdata(str, "child", "ID");
DataRelation newrelation = new DataRelation("myrelation", General.DS.Tables["parent"].Columns["id"], General.DS.Tables["child"].Columns["masterid"]);
General.DS.Relations.Add(newrelation);
listBox1.DataSource = General.DS.Tables["parent"];
listBox1.DisplayMember = "Master_name";

textBox1.DataBindings.Add("text",General.DS.Tables ["parent"],"id"));
listBox1.SelectedIndex = 0;

textBox1.DataBindings.Add("text", General.DS.Tables["parent"], "id");
listBox1.SelectedIndex = 0;

这里General是一个类,我在其中定义了类似getdata()的函数,该函数采用查询,数据表名称和主字段名称作为参数.

here General is a class where i defined the function like getdata() which take the argument which is query, datatable name, and primary field name.

然后,我想在textbox1的valuechanged事件上获取所选列表框项目的子数据.代码如下:

Then i want to get the child data of the selected listbox item on the valuechanged event of the textbox1. The code is given below :

DataRow myRow = General.DS.Tables ["parent"].Rows.Find(textBox1.Text);
Datarow [] MYARRAY = myRow.GetChildRows(General.DS.Relations ["myrelation"]]);
dataGridView1.DataSource = MYARRAY;

DataRow myRow = General.DS.Tables["parent"].Rows.Find(textBox1.Text);
Datarow[] MYARRAY = myRow.GetChildRows(General.DS.Relations["myrelation"]);
dataGridView1.DataSource = MYARRAY;

但是,当我运行代码时,datagridview1会以标题为"RowError","RowState","Table"的列显示行.和"HasErrors"并且RowState列显示值"Unchanged".在所有行中,所有其他列为空,HasErrors列具有复选框 在其中,datagridview显示为只读.我无法知道这些列是什么以及它们的外观,而我的子表没有这些列.令人惊讶的是,datagridview1将确切的行数显示为可子表的行,但具有不同的行数 列和值.谁能告诉我它是怎么发生的以及我该如何解决.

But when i run the code, the datagridview1 shows the rows with colums heading "RowError","RowState","Table" and "HasErrors" and the RowState column is showing value "Unchanged" in all the rows, all other colums empty and HasErrors column having chekboxes in it and the datagridview appears readonly. I cant know what these columns are and how they appeared while my childtable doesnot having these columns. The surprising thing is that the datagridview1 shows exact number of rows as childtable but with different columns and values. Can anyone tell me how it happened and how can i resolve it.

推荐答案

         谢谢您的发帖!我建议您在( SQL Server > SQL Server论坛 > SQL Server数据访问)论坛,位于: ( http://social.technet.microsoft.com/Forums/en/sqldataaccess/threads)

           Thank you for your post!  I would suggest posting your question in one of the (SQL Server > SQL Server Forums> SQL Server Data Access) forum located here:  (http://social.technet.microsoft.com/Forums/en/sqldataaccess/threads)

       希望对您有所帮助.

         Hope that would be helpful.

       祝你有美好的一天!

         Have a great day!

       谢谢&问候

         Thanks & regards,


这篇关于在亲子关系中发现子串.............的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-10 22:04