When you want to join strings, I recommend using the &, as this tells the compiler that you don't wish to convert the string to a number, and instead you wish to join them as strings. For example, the following will display a messagebox with the value of 10: MsgBox("5 " + " " + 5) The reason you are getting the error is that the compiler tries to convert the string to a numeric value when + is used with a number. ToString to your m_decBalance, as this will tell the compiler to treat m_decBalance as a string, like so: MsgBox("You balance is " & " " & m_decBalance.ToString) The problem is that you are joining a string with a +. MsgBox("You balance is " + " " + m_decBalance) Private Sub btnBalance_Click(sender As Object, e As EventArgs) Handles btnBalance.Click M_strName = Convert.ToString(DataReader("Name"))ĭataReader.Close() ' close data reader connectionĭbCon.Close() ' close database connection M_decBalance = Convert.ToString(DataReader("Balance")) M_strPass = Convert.ToString(DataReader("Password")) ' retrieve Password number, balance amount and name information from database "FROM Account WHERE CardNumber='" & Val(cboAccountNumbers.Text) & "' "ĭataReader.Read() ' open data reader connection StrQuery = "SELECT Name, Balance, Password " & ' specify account number of record from which data will be retrieved ' invoke when user provides account number MsgBox("Failure to communicate" & vbCrLf & vbCrLf & ex.Message) 'Output error message to user with explaination of error ' create database reader to read information from databaseĬ(DataReader("CardNumber")) SQLcmd = New MySqlCommand(strQuery, dbCon) Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.LoadĭbCon = New MySqlConnection("Server=localhost Database=test Uid=root Pwd=mysql") LblWelcome.Text = "Sorry, Password is incorrect." _ ' indicate that incorrect password was provided LblWelcome.Text = "Welcome" + " " + m_strName The CType Function takes a second argument, typename, and coerces expression to typename, where typename can be any data type, structure, class, or interface to which there exists a. ' determine if Password is correct or not For example, use Double.Parse when converting a string to a Double, and use Double.ToString when converting a value of type Double to a string. 'Assign users guessed password to variable Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnLogin.Click Can anyone help me? Here's my code: Imports MySql.Data I've tried different ways a converting it from a string to a double, I thought maybe it was because I had m_decBalance declared as a decimal, but that didn't change anything. However once I click the Check Balance button it produces the error Conversion from string "Your balance is " to type 'Double' is not valid. I'm trying to display a logged in users balance from a database in VB.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |