是否有更新,更好的方法来执行此操作...
大家好,
我正在构建数据库应用程序.表格之一由三个字段组成
I'm building a database application. One of the tables consists of three fields
AuthorID
Author_Last_Name
Author_First_Name
AuthorID
Author_Last_Name
Author_First_Name
一旦用户在数据库中输入了作者的名字和姓氏,我就不想让他们再担心了,我希望用户能够想到 Isaac Asimov ,而不必担心 Asamov,Isaac .这是初步用户界面的一部分片段:
Once the user has entered the Author's first and last names into the database I don't want them to have to worry about that any more, I want the user to be able to think of Isaac Asimov and not have to worry about Asimov, Isaac. Here is a snip of part of the preliminary user interface:
请注意,我已在列表框中串联了Author_First_Name和Author_Last_Name.用户将能够为给定标题选择尽可能多的名称.通常我会为此使用Listview控件并使用AuthorID 作为轻松转换的关键.由于Listview已有一段时间没有键值了,所以我看到的最好方法是使用两个数组:
Notice that I've concatenated the Author_First_Name and Author_Last_Name in the listbox. The user will be able to select as many names as necessary for a given title. Normally I would have used a Listview control for this and used the AuthorID as the key for easy conversions. Since Listview hasn't had a key value in a while :) the best way I see is to use two arrays:
Dim AuthID(iRecordCount) as Integer
Dim AuthName(iRecordCount) as Integer
Dim i as Integer
Dim r as DataRow
For i = 0 to iRecordCount - 1
r = dbDataTable.Rows(i)
AuthID(i) = r("AuthorID")
AuthName(i) = r("Author_First_Name") & " " _ &
r("Author_Last_Name")
lstAuthors.Items.Add (AuthName(i))
Next i
这只是填充两个数组并填充列表框.
That simply populates the two arrays and fills the listbox.
然后我将通过类似于以下内容的方式来选择与特定图书相关联的作者:
I would then select the authors associated with a specific Book by something similar to:
Dim i as Integer
Dim x as integer
Dim iRecordCount as Integer
Dim r as datarow
Dim iMatch as Integer
' In this case the datatable contains a list of all
' books matched to all selected authors
' This table has three columns
' AuthorToBookID, BookID, AuthorID
iRecordcount = db.dbDataTable.Rows.Count
' Count through records in column looking for
' the current BookID
For i = 0 to iRecordCount - 1
r = db.dbDataTable.Row(i)
' Check for match
If r("BookID") = BookID then
' Matched, now find entry in AuthID()
For x = 0 to lstAuthors.Items.Count - 1
If r("AuthorID") = AuthID(x) then
iMatch = x
Exit For
End If
Next x
' Match found select author's name
For x = 0 to lstAuthors.items.count - 1
If lstAuthors.items(x) = AuthName(iMatch) Then
lstAuthors.Items(x).Selected
Exit For
End If
Next x
End If
Next i
如果用户编辑这本书并删除或添加作者,则我将使用相同的过程,但反之,以确保所有选定的作者都在数据库表中,此外还要删除链接器表"中的任何记录.不再需要 由于用户的更改.如果我需要以这种方式编写代码,那么它不会太慢,以至于用户不会注意到.但这似乎有点...有风的.
If the user edits this book and removes or adds authors I would use the same process but in reverse to ensure all selected authors are in the database table with the addition of deleting any records in the "linker table" that are no longer needed due to user changes. If I need the write the code this way I will, it won't be slow enough for the user to notice. But it does seems sorta of... windy.
我已经浏览了vb.net中内置的许多新集合类型.尽管一对夫妇似乎抱有希望,但我找不到关于它们的足够文档来确定是否可以在双向查找中使用它们.当我开始看到线条时 像这样的代码:
I've looked through a number of the new collection types built into vb.net. Though a couple seemed to hold promise I couldn't find enough documentation on them to determine if I could use them in bidirectional lookups. When I start seeing lines of code like this one:
Public Iterator Function GetEnumerator() As IEnumerator(Of BottleOfWine) Implements IEnumerable.GetEnumerator(Of BottleOfWine)
没有任何解释,我被迫从可能性列表中检查一个,然后继续前进.
With no explanation whatsoever, I'm forced to check that one off the list of possibilities and move on.
以下是与上述代码相关的说明材料.
Here's the instructional material associated with the above code.
迭代器
Iterators
从技术上讲,迭代器用于遍历集合,并且迭代器函数在集合上执行自定义迭代.它们只能具有IEnumerable,IEnumerable(of T),IEnumerator或IEnumerator(Of T)作为返回类型.
该段继续描述它们如何使用新的Yield关键字来允许两个进程同时工作并节省时间.他们比For ... Each等更好.
The paragraph goes on to describe how these use the new Yield keyword to allow two processes to work simultaneously and save time. That they are better that For...Each, etc.
我意识到电子阅读器的普及,使得书籍像VHS和LP一样是一种濒临灭绝的格式.这个项目主要是为了我自己的利益而进行的学习练习.
I realize that with e-readers and such that books are a dying format just like VHS and LPs. This project is mainly a learning exercise for my own benefit.
谢谢.
该项目主要是出于我自己的目的而进行的学习练习.
This project is mainly a learning exercise for my own benefit.
肯,
知道我不是数据库专家,如果我们一起努力,这对您有帮助吗?我可以设置一些模仿数据库的东西,但是它根本不是[标准]数据库.
Knowing that I am NOT a database guy, would it be helpful at all if we worked on this together? I can set something up that will mimic a database but it won't be a [standard] database at all.
如果您有兴趣,请告诉我.
Let me know if you're interested.