Hi,
I am creating a game where i have made a login form thats uses the mysql database for the user accounts.
The database stores account's login info, level, XP, Coins.
all goes well when you login.
when i go to form 2 i want to say hello to the user like: Welcome User
on form 2 is a label called Levellabel.text
And also i want to show the XP amount in a progressbar.
In the database :
Level: 9
XP: 244
ID: 0000000001
when i run the app it gives me this when i change the XP to VARCHAR in the database, when changed to INT it gives error below:
Level: 0
XP: 1
ID: 2
I am getting this error when using INT in the database for XP end Level:
Error: Conversion from string "XP" to type 'integer' is not valid.
I need help because im stuck
here is the code:
Dim mMySQLConnectionString As String = "Server=localhost;Database=game;Uid=root;password =password" Dim conn As MySqlConnection Dim dr As MySqlDataReader Dim cmd As New MySqlCommand conn = New MySqlConnection() conn.ConnectionString = mMySQLConnectionString Try conn.Open() cmd.CommandText = "SELECT Level, XP, ID FROM user WHERE Username='?Username'('" & Levellabel.Text & "')" cmd.Parameters.Add(New MySqlParameter("?UserName", Usernamelabel.Text)) cmd.Connection = conn dr = cmd.ExecuteReader dr.Read() '!Here is where i want to give the value's to my label and progressbar! Levellabel.Text = dr.GetValue("Level") IDlabel.Text = (dr.GetOrdinal("ID")) 'Levellabel.Text = (dr.GetOrdinal("Level")) 'XPlabel.Text = (dr.GetValue("XP")) XPbar.Value = (dr.GetValue("XP")) Me.XPlabel.Text = dr("XP").ToString Catch myerror As MySqlException MessageBox.Show("Database Error: " & myerror.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information) Catch ex As Exception MessageBox.Show("Error: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information) Finally cmd.Parameters.Clear() conn.Close() cmd.Dispose() conn.Dispose()
|
I hope someone can help me.