Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Oct 06, 2010 10:48 AM by hareshambaliya
Member
49 Points
64 Posts
Oct 05, 2010 04:00 PM|LINK
I've two table
a). Country
1.CountryId -PK
2. Country Name
b)City
1.CityId---PK
2.CityName
3.CountryId --FK to Country table
and my code is
DataContextDataContext CityContext = new ataContextDataContext(); tblCity objCity = new tblCity(); objCity.City = "London"; objCity.CountryId= 1; CityContext.tblCities.InsertOnSubmit(objCity);
it doesn't insert any thing in data base, whereas I've similar code for Country table that works fine.
Participant
1623 Points
260 Posts
Oct 05, 2010 06:15 PM|LINK
Hi,
you haven't write
CityContext.SubmitChanges(); method as last statement of your code.
Oct 06, 2010 08:10 AM|LINK
Well spotted! and TVM
hareshambaliya Hi, you haven't write CityContext.SubmitChanges(); method as last statement of your code.
Oct 06, 2010 10:48 AM|LINK
Thanks
akverma
Member
49 Points
64 Posts
insert data in foreign key
Oct 05, 2010 04:00 PM|LINK
I've two table
a). Country
1.CountryId -PK
2. Country Name
b)City
1.CityId---PK
2.CityName
3.CountryId --FK to Country table
and my code is
<div style="position: absolute; left: -10000px; top: 25px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">FWUDataContextDataContext CityContext = new FWUDataContextDataContext();</div> <div style="position: absolute; left: -10000px; top: 25px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> tblCity objCity = new tblCity();</div> <div style="position: absolute; left: -10000px; top: 25px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> objCity.City = City.City;</div> <div style="position: absolute; left: -10000px; top: 25px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> objCity.CountryId= int.Parse(City.CountryId);</div> <div style="position: absolute; left: -10000px; top: 25px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> CityContext.tblCities.InsertOnSubmit(objCity);</div>DataContextDataContext CityContext = new ataContextDataContext(); tblCity objCity = new tblCity(); objCity.City = "London"; objCity.CountryId= 1; CityContext.tblCities.InsertOnSubmit(objCity);it doesn't insert any thing in data base, whereas I've similar code for Country table that works fine.
hareshambali...
Participant
1623 Points
260 Posts
Re: insert data in foreign key
Oct 05, 2010 06:15 PM|LINK
Hi,
you haven't write
CityContext.SubmitChanges(); method as last statement of your code.
Haresh Ambaliya
Linq Technologies
Please remember to mark as "answers" if they help
.
akverma
Member
49 Points
64 Posts
Re: insert data in foreign key
Oct 06, 2010 08:10 AM|LINK
Well spotted! and TVM
hareshambali...
Participant
1623 Points
260 Posts
Re: insert data in foreign key
Oct 06, 2010 10:48 AM|LINK
Thanks
Haresh Ambaliya
Linq Technologies
Please remember to mark as "answers" if they help
.