0
首先感謝這些論壇上的所有幫助,我發現它非常有用!不幸的是,我有一個問題,我無法弄清楚。我在vb.net上編寫了一個程序,它使用LogIn屏幕打開一個主頁,您可以在其中創建消息供其他人查看。數據只在程序啓動後更新到數據庫
我可以創建新消息,但它們不會顯示在我的datagridview中,除非我關閉該程序並重新打開它。然後他們在場。
Public Class frmMessage
Dim newMsgRow As Prototype1DataSet.MessagesRow
Dim editMsgRow As Prototype1DataSet.MessagesRow
Private Sub MessagesBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.MessagesBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Prototype1DataSet)
End Sub
Private Sub MessageForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the Prototype1DataSet.Messages table. You can move, or remove it, as needed.'
Me.MessagesTableAdapter.Fill(Me.Prototype1DataSet.Messages)
End Sub
Private Sub btn_SaveMsg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_SaveMsg.Click
'Check if inputs are valid and then saves new message and returns to Home Page'
If CheckDataInputs() Then
If frmHomePage.editMsgFlag = False Then
SaveNewMessage()
ElseIf frmHomePage.editMsgFlag = True Then
EditMessage()
End If
MessageBox.Show("Message saved", Me.Text, MessageBoxButtons.OK)
Me.Hide()
frmHomePage.Show()
End If
End Sub
Private Function CheckDataInputs() As Boolean
'Check if any inputs are left empty'
Dim InputsCheck As Boolean = True
If txt_MsgFrom.Text = "" Then
MessageBox.Show("Please state whom the message is from", Me.Text, MessageBoxButtons.OK)
Me.txt_MsgFrom.Focus()
InputsCheck = False
ElseIf txt_MsgTo.Text = "" Then
MessageBox.Show("Please enter message recipient", Me.Text, MessageBoxButtons.OK)
Me.txt_MsgTo.Focus()
InputsCheck = False
ElseIf txt_Message.Text = "" Then
MessageBox.Show("Please enter a message", Me.Text, MessageBoxButtons.OK)
Me.txt_Message.Focus()
InputsCheck = False
ElseIf txt_MsgStatus.Text = "" Then
MessageBox.Show("Please select message status", Me.Text, MessageBoxButtons.OK)
Me.txt_Message.Focus()
InputsCheck = False
End If
Return InputsCheck
End Function
Private Sub SaveNewMessage()
'Saves new message into Messages table'
newMsgRow = Prototype1DataSet.Messages.NewMessagesRow()
newMsgRow.From = txt_MsgFrom.Text
newMsgRow._To = txt_MsgTo.Text
newMsgRow.Message = txt_Message.Text
newMsgRow.Status = txt_MsgStatus.Text
newMsgRow._Date = date_Msg.Text
Prototype1DataSet.Messages.AddMessagesRow(newMsgRow)
MessagesTableAdapter.Update(Prototype1DataSet)
Prototype1DataSet.Messages.AcceptChanges()
End Sub
End Class
感謝matzone,我在AcceptChanges()後面添加了DGV.DS = Dataset.Table,它工作正常,但現在它在我的DGV中創建了一個雙輸入。當我創建另一條消息時,前面的double被刪除,但新條目有一個double ... – user2517766