所以我尝试了一个我的概念工具,我需要能够真正轻松地从数据库中读取和写入数据。我按照自己喜欢的方式设置了表单,并围绕不同的文本框和下拉框读取数据库中的数据。我已经掌握了所有工作和所有工作,但是有一个小错误,我不完全明白为什么在那里。某些文本框不会更新数据库中的文本。但它似乎只是在数据库中的数据不存在的情况下才会发生。因此,最后一行的值仍然悬挂在文本框中,因此单击“更新”实际上会将来自最后一行的字段的值更新为新行。搞砸了一切。从数据库读取/写入时设计代码流的最佳方式
现在,我最感兴趣的是代码的剪切流。布置代码来完成所有这些工作的最佳方式是什么?到目前为止,我有这样的:
这是代码在DataGridView的单元格,当点击:
Private Sub DataGridView_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView.CellClick
On Error Resume Next
selectedName = Me.DataGridView.CurrentRow.Cells(0).Value
selectedGenre = Me.DataGridView.CurrentRow.Cells(1).Value
selectedRhytm = Me.DataGridView.CurrentRow.Cells(2).Value
selectedLength = Me.DataGridView.CurrentRow.Cells(3).Value
selectedFinished = Me.DataGridView.CurrentRow.Cells(4).Value
selectedSoundFile = Me.DataGridView.CurrentRow.Cells(5).Value
txtBoxName.Text = selectedName
txtBoxGenre.Text = selectedGenre
txtBoxRhytm.Text = selectedRhytm
txtBoxLength.Text = selectedLength
txtBoxFinished.Text = selectedFinished
txtBoxSoundFile.Text = selectedSoundFile
End Sub
的“选择” - 变量都在GlobalCode.vb我的所有声明”我已经找到了所有这些供以后使用的地方。它们的定义如下:
Friend Module GlobalVariables
Friend selectedName As String = Nothing
Friend selectedGenre As String = Nothing
Friend selectedRhytm As String = Nothing
Friend selectedLength As String = Nothing
Friend selectedFinished As String = Nothing
Friend selectedSoundFile As String = Nothing
End Module
我以前没有做过这样的事情。我更像是一个设计师而不是程序员,但我真的需要尝试一个概念,所以我不确定这是否是这样做的方式。我发现它在大多数情况下都有效。但我认为熟练的程序员有一种设计代码布局的方式,因此它的效率高,清晰易读。 那么这看起来如何?
重新您的评论 - 我不知道一个可怕的很多关于适配器,说实话(我用ORM,而不是DataSet)。也许问作为另一个具体问题? – 2009-08-08 12:55:02