I've been messing around trying to make a signup page in Visual Studio, and I can't seem to get it to work.
- Database name = User
- Columns which data to be inserted into = Username & Password
When I execute the code, it returns the message "Data Saved" which would lead me to believe that it had worked, but when I look at the table data, nothing has changed..
Public Class SignUp
Dim mysqlConn As Data.SqlClient.SqlConnection
Dim command As Data.SqlClient.SqlCommand
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
mysqlConn = New Data.SqlClient.SqlConnection
mysqlConn.ConnectionString = ("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\NewFolder1\Members.mdf;Integrated Security=True")
Dim RowsAffected As Integer
Try
mysqlConn.Open()
Dim query As String = "INSERT INTO [User] (username, password) VALUES (@Username, @Password)"
command = New SqlClient.SqlCommand(query, mysqlConn)
Dim paramUsername As New SqlClient.SqlParameter() With {.ParameterName = "@Username", .Value = TextBox1.Text, .Size = 50, .SqlDbType = SqlDbType.VarChar}
Dim paramPassword As New SqlClient.SqlParameter() With {.ParameterName = "@Password", .Value = TextBox2.Text, .Size = 50, .SqlDbType = SqlDbType.VarChar}
command.Parameters.Add(paramUsername)
command.Parameters.Add(paramPassword)
RowsAffected = command.ExecuteNonQuery
mysqlConn.Close()
If 0 < RowsAffected
Then MessageBox.Show("Data Saved")
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
mysqlConn.Dispose() 'closes connection
End Try