如何增加列中的值? [英] How about incrementing values in a column ?

查看:68
本文介绍了如何增加列中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 在我的项目中使用动态
这是我的桌子详细信息
tblBidtree(table)
列名称
btID
btDID
btDocType
btNodeID
btName
btParentNodeID
btType
btDetails
btDelStatus

btNodeID是第4列

这是我表中添加的记录
              nbsp; bsp    列btNodeID
              nbsp; bsp          \/

128	125	YTB1	-1	New 1	0			False
129	125	YTB1	-2	New 1	1	Textbox	dddd	False




在editng之后,当我在树上再添加一个节点时,这个

128	125	TPR1	-1	New 1	0	TextBox	hhh	        False
129	125	TPR1	-2	New 1	1	Textbox	dddd	        False
130	125	TPR1	-1	New 2	0	Textbox	after edit	False




但是在将记录编辑为垂直ID后
应该这样保存

128	125	TPR1	1	New 1	0 TextBox hhh			False
129	125	TPR1	2	New 1	1	Textbox	dddd	        False
130	125	TPR1	3	New 2	0	TextBox after Edit      False



负值应为btNodeID的正值.如果btNodeID为1,2,并且不应再次重复1,则应递增为3.如1,2,3
我只想更改btNodeID
请建议我如何在循环或简单方法中执行此操作.

可以为这篇文章提供任何帮助..

或者如何像主键一样增加btNodeID.我们可以为两列设置自动增加?

解决方案

您可以简单地将所有他们以-1一对一的方式
并为数组或列表中的每个项目添加btNodeID.

如果列表中已经存在btNodeID,请找到列表的最大值,并使btNodeID = maxValue +1.

更新:
如果我理解正确的问题:

由于有了数据集,因此您可以执行以下操作:

 DataTable表=数据集.Tables[ 0 ];
List< int> list =  List< int>();
 foreach (在表中的数据行行.)
{
     int  btNodeID =  int  .Parse(row [ 3 ].ToString())* -1;
    如果(列表.计数>   0  && list.包含(btNodeID))
    {
        btNodeID = list.Max()+  1 ;
    }
    list.Add(btNodeID);
    row [ 3 ] = btNodeID;
    row.AcceptChanges();
}
table.AcceptChanges();



不过,您可能需要添加更多的控制语句.


您的主题行已延迟.每个询问的人都希望有人可以回答他们.弄清楚你想要什么.

您通过执行更新而不是插入操作来增加值,并将列设置为等于其值+1.您的问题有点荒谬,但这似乎是问题的核心,并且它的确是就这么简单.将值设置为所需的值,这就是数据库的工作方式.


hi am using dynamic in my project
here is my table details
tblBidtree(table)
columns name
btID
btDID
btDocType
btNodeID
btName
btParentNodeID
btType
btDetails
btDelStatus

btNodeID is 4th column

this is the added record in my table
                             column btNodeID
                                   \/

128	125	YTB1	-1	New 1	0			False
129	125	YTB1	-2	New 1	1	Textbox	dddd	False




this after editng when i add one more node to tree

128	125	TPR1	-1	New 1	0	TextBox	hhh	        False
129	125	TPR1	-2	New 1	1	Textbox	dddd	        False
130	125	TPR1	-1	New 2	0	Textbox	after edit	False




but after editing records to perticular id
should save like this

128	125	TPR1	1	New 1	0 TextBox hhh			False
129	125	TPR1	2	New 1	1	Textbox	dddd	        False
130	125	TPR1	3	New 2	0	TextBox after Edit      False



negative value should positive for btNodeID ..and if btNodeID is 1,2 and it should not repeat again 1 it should increment to 3..like 1,2,3
i want only changes in btNodeID
please suggest me how can i do this in loop or in simple method..

can any one help for this post..

or how can i increment btNodeID like primary key..we can set autoincrement for two columns??

解决方案

You can simply multiply all of them by -1 one by one.
And add btNodeID for each item in an array or list.

If a btNodeID already exists in list, find max value of list and make btNodeID = maxValue + 1.

Update:
If I understood question right:

Since you have a dataset, you can do something like following:

DataTable table = dataset.Tables[0];
List<int> list = new List<int>();
foreach (DataRow row in table.Rows)
{
    int btNodeID = int.Parse(row[3].ToString()) * -1;
    if (list.Count > 0 && list.Contains(btNodeID))
    {
        btNodeID = list.Max() + 1;
    }
    list.Add(btNodeID);
    row[3] = btNodeID;
    row.AcceptChanges();
}
table.AcceptChanges();



You probably need to add more control statements though.


Your subject line is retarded. Every person asking is hoping someone can answer them. Make it clear what you want.

You increment a value by doing an update instead of an insert and settings the column to be equal to it''s value + 1. Your question is somewhat nonsensical, but that seems to be the core of it, and it''s really as easy as that. Set the value to what you want it to be, that''s how DBs work.


这篇关于如何增加列中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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