我似乎无法让我的程序写入我的数据集。任何意见都表示赞赏。
添加按钮代码:
Private Sub AddPlayerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddPlayerToolStripMenuItem.Click
Using dialogue As New newMatchForm
If dialogue.ShowDialog = DialogResult.OK Then
Dim prating As Integer
Dim givendate As String = newMatchForm.givenDate
Dim p1 As String = newMatchForm.givenP1
Dim p2 As String = newMatchForm.givenP2
Dim winner As String = newMatchForm.givenWinner
prating = prating + newMatchForm.prating
Dim newrow As PvPLeaderboard.DataSet1.MatchesRow = CType(DataSet1.Matches.NewRow, PvPLeaderboard.DataSet1.MatchesRow)
newrow._Date = givendate
newrow.Player_1 = p1
newrow.Player_2 = p2
newrow.Winner = winner
DataSet1.Matches.Rows.Add(newrow)
Me.MatchesTableAdapter.Update(Me.DataSet1.Matches)
End If
End Using
End Sub
属性:
Public ReadOnly Property givenDate() As String
Get
Return Me.DateTimePicker1.Text
End Get
End Property
Public ReadOnly Property givenP1() As String
Get
Return Me.player1Combobox.SelectedItem.ToString
End Get
End Property
Public ReadOnly Property givenP2() As String
Get
Return Me.player2Combobox.SelectedItem.ToString
End Get
End Property
Public ReadOnly Property givenWinner() As String
Get
If player1RadioButton.Checked = True Then
Return Me.player1Combobox.SelectedItem.ToString
Else
Return Me.player2Combobox.SelectedItem.ToString
End If
End Get
End Property
Public ReadOnly Property prating() As Integer
Get
If player1RadioButton.Checked = True Then
Return CInt(Me.p1RatingLabel.Text.)
Else
Return CInt(Me.p2RatingLabel.Text)
End If
End Get
End Property
对话确定按钮:
Private Sub addButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addButton.Click
If player1Combobox.SelectedIndex = player2Combobox.SelectedIndex Then
MessageBox.Show("Cannot match the same players, please select a valid match-up.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf player1RadioButton.Checked = False AndAlso player2RadioButton.Checked = False Then
MessageBox.Show("Please select a winner", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Me.DialogResult = DialogResult.OK
Me.Close()
End If
End Sub
在我的主窗体上,我有一个“添加按钮”。单击它时,它会打开一个对话框,接受新数据行的输入并将属性返回到主窗体。问题是,它不写数据集的新行。
PS。是的我将数据集命名为“Dataset1”,是的,我知道我不应该。
答案 0 :(得分:0)
通常,在向数据集添加行时,需要在数据集中创建新行的过程。我原本希望看到如下代码:
newrow = Dataset1.Matches.Newrow
此代码将在您开始添加列数据之前进行。