0
我似乎無法將我的程序寫入我的數據集。任何輸入讚賞。寫入數據集問題
添加按鈕代碼:
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
對話OK按鈕:
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
在我的我的主要形式,我有一個「添加按鈕」,當它。被點擊後,它會打開一個對話框,接受新數據行的輸入並將屬性返回給主窗體。問題是,它是d不要將新行寫入數據集。
PS。是的,我給數據集命名爲「Dataset1」,是的,我知道我不應該這樣做。
您調試了嗎? Me.MatchesTableAdapter.Update(Me.DataSet1.Matches)是否被調用? – Paparazzi
in AddPlayerToolStripMenuItem_Click爲什麼你會從「newMatchForm」獲取值,這是你輸入表單的類而不是作爲對象的「對話」?也許我錯了? –