So I have a text box in a form. The test box needs to take the value entered and insert it into a column within a row in MySQL.
I know it's connecting to the MySQL online, I have a message box telling me so upon a successful connection. I'm just having problems adding the value. Here's my code:
Public Class frmOptions Dim ServerString As String = "server=db4free.net; Port =3306; user id=dailylogmain; password=XXXXXXX; database=dailylogmain;" Dim SQLConnection As MySqlConnection = New MySqlConnection Private Sub frmOptions_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SQLConnection.ConnectionString = ServerString Try If SQLConnection.State = ConnectionState.Closed Then SQLConnection.Open() MsgBox("Connected...") Else SQLConnection.Close() MsgBox("Connection failed") End If Catch ex As Exception End Try End Sub Private Sub btnSaveStats_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim SQLStatement As String = "INSERT INTO users(stat1) VALUES('" & Me.txtStat1.Text & "')" SaveStats(SQLStatement) End Sub Public Sub SaveStats(ByRef SQLStatement As String) Dim cmd As MySqlCommand = New MySqlCommand With cmd .CommandText = SQLStatement .CommandType = CommandType.Text .Connection = SQLConnection .ExecuteNonQuery() End With SQLConnection.Close() MsgBox("Record Added") SQLConnection.Dispose() End Sub
When I try to submit, I'm not getting the messagebox saying "record added", so something is not right. I'm not getting any errors, just nothing is happening.
Does anyone have any ideas?