如何将一张表中的信息插入到其 LINK 表中?

发布于 2024-10-08 07:13:16 字数 592 浏览 0 评论 0原文

我正在尝试构建一个 asp.net 应用程序,其中有三个表。

tblRoute
tblHalte
tblHalteRoute

我想将一个routeID插入到tblHalteRoute中,并且对于每个routeID,多个halteID的

TblRoute具有所需的字段(routeID(1) &
allHaltes[halteID1,halteID2,halteID3])
-->所以每条路线都有多个 Haltes,我可以通过解析 allHaltes 字段并使用 IDS 来访问它们。

我想做的是像这样更新 tblHalteRoute :

tblRoute.routeID(1), tblRoute.allHaltes(halteID1)
tblRoute.routeID(1), tblRoute.allHaltes(halteID2)
tblRoute.routeID(1), tblRoute.allHaltes(halteID3)

将这些值插入到 tblHalteRoute 中。我真的不确定在哪里查找或如何开始,我尝试在选择之前使用带有插入的子查询,但没有成功。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长亭外,古道边 2024-10-15 07:13:16

如果我理解正确,您正在尝试旋转数据 - 例如,

Route 1 Halte 1
Route 1 Halte 2
Route 1 Halte 3

-->

Route 1 Halte 1 Halte 2 Halte 3

我还假设您的意思是 LINQ 而不是 LINK (如数据访问机制中)

如果是这种情况,您可以编写一个执行以下操作的函数

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

:值得注意的是,您假设您的路由表将具有比 Ids 更多的 Id 字段=这对于您的应用程序来说可能是一个有效的假设,但即使是这样,对我来说也感觉很危险 - 我建议您存储正确地执行此操作(即保持相关性),然后根据需要For Each每一行 - 那么可用的 Id 数量就没有限制。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文