如何从预创建数据库转换为程序数据库? [英] How Do I Convert From Pre-create Database to Programatic Database?

查看:71
本文介绍了如何从预创建数据库转换为程序数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定我是否正确地问过这个问题,但在我解释时请耐心等待。



我创建了一个程序,所有编码都完成了,一切都完成了我只剩下一件事,那就是让用户可以保存并加载他们的值。该程序是口袋妖怪的EV追踪器:黑暗的黎明。 Form1有



6次数量(HPAmount,AtkAmount,DefAmount,SpAtkAmount,SpDefAmount和SpdAmount)



3个按钮。 AddButton从AddPoke.Text获取文本并将其添加到名为PokeTeam的组合框中,并创建数据库记录,其中数据库中的Pokemon值等于AddPoke.Text。 Removebtn从PokeTeam中找到与AddPoke.Text相同的组合框项并将其删除,并从数据库中删除Pokemon值等于AddPoke.Text的记录。第三个按钮是添加EV按钮,根据在Defeated组合框中选择的口袋妖怪增加适当的numupdown控件。



击败的组合框由第三个填充combobox名为Training。



PokeTeam组合框从数据库中提取记录,以便数据库中列出的每个小宠物都有一个项目。 numupdown控件直接链接到数据库,以便每次更改值时更新PokeTeam中选择的pokemon记录。



这是我需要更改的内容。当我开始这个项目时,我创建了一个访问数据库并将其链接到项目。该数据库由一个名为PokemonTable的表组成。 PokemonTable由7列组成:Pokemon,HPValue,AtkValue,DefValue,SpAtkValue,SpDefValue和SpdValue。我使用MS Access和现在设置程序的方式创建了数据库,它在程序启动时自动加载数据库。我想在一切完成后创建一个保存代码会更容易。我没有指望的是学习如何从预先创建的MS Access数据库更改为程序启动时创建的数据库的难度。



I将详细介绍我在使用当前数据库时使用的所有编码。有人可以向我详细解释并使用替换编码,如何将我的程序从预先创建的数据库转换为可保存/可加载的文件。



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







'This part is in the base form1 class

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

    'Adds the text from AddPoke.Text to PokeTeam.Items
    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);"

        'Adds a record to the database with AddPoke.Text as the Pokemon column and gives 0 EV to each stat

        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





我可以继续提供更多代码但是我相信如果你帮助了解这些代码,我可以弄清楚其余部分。如果你想下载所有文件并查看更多代码,我会在下面发布一个链接(我知道我从制作这个程序中学到了很多,所以也许其他一些新手可以使用它。)谢谢你提前。



http://www.4shared。 com / zip / EhaoiywUce / PDod_EV_Tracker_20.html [ ^ ]

推荐答案

从我的评论中发布链接作为正式解决方案 - 使用VB.NET以编程方式创建Microsoft Access数据库 [ ^ ]
Posting the link from my comments as the formal solution - Create Microsoft Access Database Programmatically using VB.NET[^]


这篇关于如何从预创建数据库转换为程序数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆