在运行时将随机行从一个表复制到另一个表中
我有一个数据库,里面有两个表。一个是项目表(表 1),另一个是当前项目表(表 2)。 在表单加载时,我需要从 table1 中生成随机数量的项目并用它们填充 table2 。我试图做这样的事情:
While numberofitems >= 1
Dim i As Integer
index = myGenerator.Next(_minitem, _maxitem)
i = _itemsListBindingSource.IndexOf(index)
_bindingSource.Add(_itemsListBindingSource.Item(i))
numberofitems -= 1
End While
Me.ItemsTableAdapter1.Fill(Me.Items2DataSet1.Items)
但这根本不起作用。任何人都可以提供任何想法吗?
I have a database that has two tables in it. One is a table of items (table1) and the other is the table of current items (table2).
On form load I need to generate a random amount of the items from table1 and populate table2 with them. I was trying to do something like this:
While numberofitems >= 1
Dim i As Integer
index = myGenerator.Next(_minitem, _maxitem)
i = _itemsListBindingSource.IndexOf(index)
_bindingSource.Add(_itemsListBindingSource.Item(i))
numberofitems -= 1
End While
Me.ItemsTableAdapter1.Fill(Me.Items2DataSet1.Items)
But that wasn't working at all. Can anyone offer any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试我的解决方案(.net 3.5)。我创建了一个带有“Table1”和“Table2”以及表适配器的类型化数据集(在另一个名为 dsMain.xsd 的文件中)。我用数据库中“Table1”中的数据填充“SourceTable”,然后根据“SourceTable”中的行数抓取随机行并将它们放入“TargetTable”中。一旦“TargetTable”中有我的数据,我就使用“Update”语句将其提交到数据库。
Try my solution (.net 3.5). I created a typed dataset with a "Table1" and a "Table2" with tableadapters (in another file called dsMain.xsd). I fill my "SourceTable" with data from "Table1" in the DB, then I grab random rows based on the number of rows in "SourceTable" and place them in "TargetTable". Once "TargetTable" has my data in it, I commit it to the database using an "Update" statement.