Ive only recently starting fiddling with Visual Basic Express and Sql Databases.
Ive managed to get a database up and running, and can query information from it. I have even created a form that can add a new entry to the table im using.
The first form has a ComboBox that list the PlayerNames in my table. Form2 allows you to add a new name to the table, but anything I add isnt immediately updated in Form1. I have to relaunch the program to see the new entries. Even then, these new entries dont seem to be permanent as they eventually dissappear.
The code I have for Form1:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim db = New PlayerTestDataContextDataContext()
Dim PlayerList = From List In db.Players
Select List.PlayerName
For Each PName In PlayerList
cbPList.Items.Add(PName)
Next
End Sub
Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
frmNewPlayer.Show()
End Sub
End Class
The code for Form2:
Private Sub btnCPlayer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCPlayer.Click
Dim db = New PlayerTestDataContextDataContext()
If txtNewPlayer.Text = "" Then
lbWarning.Text = "Please enter a name!"
Else
Dim Plyr As New Player With {
.PlayerName = txtNewPlayer.Text}
db.Players.InsertOnSubmit(Plyr)
db.SubmitChanges()
Me.Close()
End If
End Sub
Not sure what is going wrong here…any help is appreciated. If I have overlooked an obvious answer around here forgive me, Im not sure what I need to be looking for.
That should do the trick. But you need to do some reading …