D
David
Suppose I have the following database:
CREATE TABLE Locations
(
int id identity not null,
city varchar(50)
)
CREATE TABLE People
(
name varchar(100),
int fk_Location references Locations(id)
)
And I have an XML file that looks like:
<People name="Fred" location="Atlanta" />
<People name="Sally" location="Atlanta" />
<People name="John" location="Los Angeles" />
<People name="Mark" location="New York" />
I want to add a record to People for every <People> in the XML file.
If there is a row in Locations where city equals the "location"
attribute in <People>, I want fk_Location equal to the existing
Locations.id, otherwise I want to create a new row in Locations where
city is the "location" attribute.
I know I can create a blank DataSet and use DataSet.ReadXml(), but
this creates a People table with a location column, rather than a
foreign key to a Locations table.
What's the best way to accomplish this? (Preferably in C#)
Thanks
CREATE TABLE Locations
(
int id identity not null,
city varchar(50)
)
CREATE TABLE People
(
name varchar(100),
int fk_Location references Locations(id)
)
And I have an XML file that looks like:
<People name="Fred" location="Atlanta" />
<People name="Sally" location="Atlanta" />
<People name="John" location="Los Angeles" />
<People name="Mark" location="New York" />
I want to add a record to People for every <People> in the XML file.
If there is a row in Locations where city equals the "location"
attribute in <People>, I want fk_Location equal to the existing
Locations.id, otherwise I want to create a new row in Locations where
city is the "location" attribute.
I know I can create a blank DataSet and use DataSet.ReadXml(), but
this creates a People table with a location column, rather than a
foreign key to a Locations table.
What's the best way to accomplish this? (Preferably in C#)
Thanks