Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

modify records in a DataView with index no. instead of unique ID?

Status
Not open for further replies.

dwfresh

Programmer
Oct 10, 2002
10
US
HI, I have a question.
I have an XML file with calendar events. When a user clicks on a particular day in my Calendar, the events for that day are shown (using a DataView).

My XML file has this structure:
<Calendar>
<Event>
<ShortDesc>first event</ShortDesc>
<DetailDesc>description</DetailDesc>
<EventDate>12/25/2002</EventDate>
<StartTime>8:00AM</StartTime>
<EndTime>11:30AM</EndTime>
</Event>
<Event>
<ShortDesc>second event</ShortDesc>
<DetailDesc>description</DetailDesc>
<EventDate>12/25/2002</EventDate>
<StartTime>6:00PM</StartTime>
<EndTime>7:30PM</EndTime>
</Event>
..........
</Calendar>

very simple.
I then put the data into a DataView and bind to a DataGrid.

The problem I am having is deleting/updating events in the DataView, which will actually link to the correct underlying Datatable Row.
Is it imperative that I have some sort of 'unique' ID/element/attribute in this XML file, or can I just link the selected index number of the DataView to the correct DataRow in the DataTable ?
What's the best way to accomplish this ?

I'm pretty new to .NET and programming so any help will be greatly appreciated !
thanks!!
 
The safest way to do this is to have an eventID. Yes, you could work off of an index#, but if your events somehow got sorted between postbacks, or any other wierdness occured, then you'd update the wrong one.

Heuristic:
ALWAYS ALWAYS ALWAYS have a uniqueID for anything and everything you deal with. Period.

You will save yourself alot of headaches if you always follow that rule.

:)
paul
penny1.gif
penny1.gif
 
Thanks Paul !
I understand... so I have one more silly question.
SO let's say I create another element <EventID> in my XML file.
how would I go about generating a unique ID# to fill this element each time I add a new event?

I was thinking that I could do something like start with 1 and just count up, 1,2,3,4,5,6,7,8. and do somehting like
'int eventid = dataset.Tables[0].Rows.Count + 1;'

but i know this is silly, cuz events will be deleted and I will have events with the same <EventID> #?

so how would someone program this to make sure that each <EventID> # is unique ?

I know this is a total rookie programming question, but any help would be great!!
thanks!!
 
Rather than trying to extrapolate the next id from the list (which you could do using the MAX() aggregate function if you want to look into it), I would suggest persisting the currentID perhaps in another file...

Whenever a new record is added, just go there, grab the number, increment it, and close it. Simple and effective.

-paul
penny1.gif
penny1.gif
 
exactly what i was thinking, thanks for the advice paul!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top