Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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??
Posted
Updated 15-Aug-12 19:48pm
v13
Comments
Sergey Alexandrovich Kryukov 23-Jul-12 1:38am    
Makes no sense.
--SA
ythisbug 23-Jul-12 2:00am    
i updated my question.thank u
Sergey Alexandrovich Kryukov 27-Jul-12 19:04pm    
Better, thank you. I think you already got an answer. Consider accepting it formally (green button).
--SA
ythisbug 28-Jul-12 0:47am    
no its not working?i tried tat code
ythisbug 28-Jul-12 2:34am    
i just want to increment using compute(max)


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:

C#
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.
 
Share this answer
 
v3
Comments
ythisbug 23-Jul-12 2:40am    
thanks sderen. can u suggest me more about this answer..i think in your post i will get answer.
sderen 23-Jul-12 2:55am    
You are welcome.
How do you add these datas to database.

Are you trying to apply these changes in .net side(i assume it from tags) or at database side?

I may be able to provide a better answer if you tell me details about these.
ythisbug 23-Jul-12 3:02am    
while editing am calling delete function den am inserting data.am using sp to insert data via for loop..and with the help of dataset dtBidtree
ythisbug 23-Jul-12 3:02am    
in .net side
sderen 23-Jul-12 3:23am    
see my updated answer please.
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.
 
Share this answer
 
Comments
ythisbug 23-Jul-12 1:59am    
thank you i updated
Christian Graus 23-Jul-12 2:01am    
Good lord, just shoot me. That's more useless.
ythisbug 23-Jul-12 2:07am    
again wat have to modify graus...??
Christian Graus 23-Jul-12 2:29am    
'dont know how to ask question for this?please suggest?' How about incrementing values in a column ? Anything is better than that. It's not about making it pretty, a good subject attracts people who cxan help you.
ythisbug 23-Jul-12 2:33am    
ya :) for that only i din knew how to ask so thout reader will suggest me..thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900