I am not sure if I asked this correctly but bear with me while I explain.
I created a program, all the coding and everything is done, there is only one thing left for me to do and that's to make it so the user can save and load their values. The program is an EV Tracker for Pokemon: Dawn of Darkness. Form1 has
6 numupdowns (HPAmount, AtkAmount, DefAmount, SpAtkAmount, SpDefAmount, and SpdAmount)
3 buttons. The AddButton that takes the text from from AddPoke.Text and adds it to a combobox named PokeTeam and also creates a database record where the Pokemon value in the database is equal to AddPoke.Text. The Removebtn finds the combobox item from PokeTeam that is equal to AddPoke.Text and removes it, and also deletes the record from the database where the Pokemon value is equal to AddPoke.Text. And the third button is the Add EV button that increments the appropriate numupdown control based on what pokemon is selected in the Defeated combobox.
The Defeated combobox is populated by a third combobox named Training.
The PokeTeam combobox pulls the records from the database so that there is one item for each pokemon listed in the database. The numupdown controls are directly linked into the database so that the record for the pokemon selected in PokeTeam is updated everytime a value changes.
This is what I need to change. When I began this project I created an access database and linked it to the project. The database consists of one table named PokemonTable. The PokemonTable consists of 7 columns: Pokemon, HPValue, AtkValue, DefValue, SpAtkValue, SpDefValue, and SpdValue. I created the database using MS Access and the way the program is setup right now, it automatically loads the database when the program starts. I figured it would be easier to create a save code after everything was finished. What I didn't count on was the difficulty of learning how to change from a pre-created MS Access database to one that is created when the program starts.
I will detail all the coding I used when working with the current database. Can Someone explain to me, in detail and with replacement coding, how to convert my program from a pre-created database to a savable/loadable file.
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
PokeTeam.Items.Clear()
DbConnection.ConnectionString = strConnectionString
DbConnection.Open()
Dim SqlQry As String = "SELECT * FROM PokemonTable"
DbConnection = New OleDbConnection(strConnectionString)
Try
' Open connection
DbConnection.Open()
'create data adapter
Dim da As OleDbDataAdapter = New OleDbDataAdapter(SqlQry, DbConnection)
'create dataset
Dim ds As DataSet = New DataSet
'fill dataset
da.Fill(ds, "PokemonTable")
'get data table
Dim dt As DataTable = ds.Tables("PokemonTable")
'display data
Dim row As DataRow
For Each row In dt.Rows
PokeTeam.Items.Add(row("Pokemon"))
Next row
Catch ex As OleDbException
MsgBox("Error: " & ex.ToString & vbCrLf)
Finally
' Close connection
DbConnection.Close()
End Try
End Sub
Dim DbConnection As New OleDbConnection
Dim DbCommand As New OleDbCommand
Dim DbInsert As New OleDbCommand
Dim DbUpdate As New OleDbCommand
Dim DbDelete As New OleDbCommand
Dim strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
System.Environment.CurrentDirectory & "\EV Tracker.mdb"
Private Sub AddButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddButton.Click
If AddPoke.Text.Length > 3 Then
PokeTeam.Items.Add(AddPoke.Text)
DbInsert.CommandText = "INSERT INTO PokemonTable (Pokemon, HPValue, AtkValue, DefValue, SpAtkValue, SpDefValue, SpdValue) VALUES (@Pokemon, @HPValue, @AtkValue, @DefValue, @SpAtkValue, @SpDefValue, @SpdValue);"
DbInsert.CommandType = CommandType.Text
DbInsert.Connection = DbConnection
DbInsert.Parameters.AddWithValue("@Pokemon", AddPoke.Text)
DbInsert.Parameters.AddWithValue("@HPValue", 0)
DbInsert.Parameters.AddWithValue("@AtkValue", 0)
DbInsert.Parameters.AddWithValue("@DefValue", 0)
DbInsert.Parameters.AddWithValue("@SpAtkValue", 0)
DbInsert.Parameters.AddWithValue("@SpDefValue", 0)
DbInsert.Parameters.AddWithValue("@SpdValue", 0)
DbInsert.ExecuteNonQuery()
End If
DbInsert.Dispose()
AddPoke.Text = ""
End Sub
I could go on giving more code but I believe if you help with these bits of code I can figure out the rest. I'll post a link below if you want to download all the files and see more of the code (I know I learned a lot from making this program so maybe some other newbie will be able to make use of it).Thank you in advance.
http://www.4shared.com/zip/EhaoiywUce/PDod_EV_Tracker_20.html[
^]