从字符串获取词法值 [英] Get a lexical value from a string

查看:68
本文介绍了从字符串获取词法值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我想以一种特定的方式对表格进行排序.为此,让我们将表命名为"Customers".客户从Northwind-db获取数据.

我喜欢对表格进行排序的方式如下.首先,我想将标记的行移到表的顶部(索引:0、1、2等).表格的其余部分(即未标记的行)应按字母顺序排列,就像在字典中根据vch列一样.

在我的第一次尝试中,我按字母顺序对表进行排序,并尝试通过删除标记行并将其插入顶部来将其移到顶部.

 DataRow selectedRow = sourceTable.Rows.Find(key);
    DataRow newRow = sourceTable.NewRow();
    newRow.ItemArray = selectedRow.ItemArray;
    sourceTable.Rows.Remove(selectedRow);
    sourceTable.Rows.InsertAt(newRow,pos);


这可行,但引起了问题.我在客户"表中有一些子表,每次删除客户"中的一行以将其插入顶部时,其子行也将被删除.我找不到任何方法来暂停这段代码的关系.有BeginEdit和EndEdit,但是这些功能只是暂停编辑条件而不是删除条件.情况也是这样:

 dataSet1.EnforceConstraints =  false ;
// 对数据集执行一些操作
dataSet1.EnforceConstraints =  true ;



也许我可以在客户"表中添加一个额外的排序列,其中每一行都有一些整数值,而标记的行具有最少的值.如果我设置DefaultView-Object的Sort-property,则这些标记的行将最终出现在顶部.
现在的问题是,对于未标记的行,我需要一个词法值.我找不到一些给我字符串值的函数.只是将两个字符串与string.Compare比较不符合我的目的.我需要这样的东西:

 Int iAtanasia = GetInt(" );
//  iAtanasia == 10 
    Int iPeter = GetInt(" );
//  iPeter == 50; 



有人对我如何解决这个问题有很好的建议吗?如果您知道一种方法,我可以采用其他解决方案进行描述的排序.

谢谢
/Sahit

解决方案

为什么不使用DataSet中的排序工具?这样,您不必移动任何行...

MSDN可以帮助:数据集中的筛选和排序 [ ^ ]

Hello Everybody!

I would like to sort a table in a specific way. Let us name the table "Customers" for this purpose. Customer gets its data from Northwind-db.

The way I like to sort the table is the following. First I would like to move marked rows on the top of the table (index: 0, 1, 2, etc). The rest of the table, i.e. the unmarked rows, should be ordered alphabetically like in a lexicon according a vch-column.

In my first try I ordered the table alphabetically and tried to move the marked rows on the top by removing those and insert them on the top.

DataRow selectedRow = sourceTable.Rows.Find(key);
    DataRow newRow = sourceTable.NewRow();
    newRow.ItemArray = selectedRow.ItemArray;
    sourceTable.Rows.Remove(selectedRow);
    sourceTable.Rows.InsertAt(newRow, pos);


This works but caused a problem. I have some child tables to the table "Customers" and each time I remove a row in "Customers" to insert it on the top its child rows are removed as well. I could not find any way to suspend the relations for this piece of code. There are BeginEdit and EndEdit, but those functions just suspend editing conditions not deleting condition. The same is the case for this:

dataSet1.EnforceConstraints = false;
// Perform some operations on the dataset
dataSet1.EnforceConstraints = true;



Maybe I can add an extra sort column to the table "Customers" where each row has some integer value and the marked rows has the least values. Those marked rows would then end up on the top if I set the Sort-property of the DefaultView-object.
The problem now is that I need a lexical value for the unmarked rows. I could not find some function giving me a value for a string. Just compare two strings with string.Compare does not fit my purpose. I would need something like this:

Int iAtanasia = GetInt("Atanasia");
// iAtanasia == 10
    Int iPeter = GetInt("Otto");
//iPeter == 50;



Do someone have a good suggestion how I could solve this. I’m open to other solutions to make the described sorting if you know a way.

Thanxs
/Sahit

解决方案

Why don''t you use the sort facilities in the DataSet? That way, you don''t have to move any rows...

MSDN can help: Filtering and Sorting in Datasets[^]


这篇关于从字符串获取词法值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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