How do I INSERT info from one table into its LINK table?
I'm trying to build an asp.net application, where I have three tables.
tblRoute
tblHalte
tblHalteRoute
I want to开发者_开发问答 insert a routeID into tblHalteRoute and for every routeID multiple halteID's
TblRoute has the needed fields (routeID(1) &
allHaltes[halteID1,halteID2,halteID3]) --> so Every route has multiple Haltes that I can access by parsing the allHaltes field and using the IDS.What I want to do is update tblHalteRoute like this:
tblRoute.routeID(1), tblRoute.allHaltes(halteID1)
tblRoute.routeID(1), tblRoute.allHaltes(halteID2)
tblRoute.routeID(1), tblRoute.allHaltes(halteID3)
inserting these values into the tblHalteRoute .. I'm really not sure on where to look or how to start, I tried using SUBquerys with an Insert before a select, but no success.
If I understand you correctly, you're trying to pivot data - eg
Route 1 Halte 1
Route 1 Halte 2
Route 1 Halte 3
-->
Route 1 Halte 1 Halte 2 Halte 3
I'm also assuming you mean LINQ not LINK (as in the data access mechanism)
If this is the case, you could write a function that does something like:
Dim MyNewRow = New tblHalteRoute
Dim Routes = MyRoutes.Where(function(x) x.RouteId = 1).OrderBy(function(x) x.RouteId)
MyNewRow.Route1 = Routes.First.id
MyNewRow.Route2 = Routes.Skip(1).First.id
MyNewRow.Route£ = Routes.Skip(2).First.id
It's worth nnoting that you're making an assumption that your Route table will have more Id fields than there are Ids = This may be a valid assumption for your app but even if it is, it feels dangerous to me - I'd suggest you store this properly (ie keep it relational) and then just For Each
each row as required - then there's no limit to the number of Ids available.
精彩评论